예제 #1
0
        public static float CalcCliff(int x, int z, float[] noise)
        {
            var index = NoiseMap.GetIndex(x, z);

            float cliff = 0f;

            if (x > 0)
            {
                cliff = Math.Max(cliff, Math.Abs(noise[index] - noise[NoiseMap.GetIndex(x - 1, z)]));
            }

            if (z > 0)
            {
                cliff = Math.Max(cliff, Math.Abs(noise[index] - noise[NoiseMap.GetIndex(x, z - 1)]));
            }

            if (x < 15)
            {
                cliff = Math.Max(cliff, Math.Abs(noise[index] - noise[NoiseMap.GetIndex(x + 1, z)]));
            }

            if (z < 15)
            {
                cliff = Math.Max(cliff, Math.Abs(noise[index] - noise[NoiseMap.GetIndex(x, z + 1)]));
            }

            return(cliff);
        }
예제 #2
0
        private void GenerateTerrain(ChunkColumn column, float[] noise)
        {
            var heightMap = noise;

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    /* var biome = biomes[NoiseMap.GetIndex(x, z)];
                     *
                     * byte biomeId = (byte) biome.Id;
                     * if (ApplyBlocks)
                     * {*/
                    var h = (int)heightMap[NoiseMap.GetIndex(x, z)];

                    var height = h;
                    for (int y = 0; (y <= height || y <= Preset.SeaLevel) && y < 255; y++)
                    {
                        if (y > height)
                        {
                            if (y < Preset.SeaLevel)
                            {
                                column.SetBlock(x, y, z, new Water());
                            }
                            else
                            {
                                column.SetBlock(x, y, z, new Air());
                            }
                        }
                        else if (y == height)
                        {
                            column.SetBlock(x, y, z, new Stone());
                            //    column.SetBlock(x, y, z, BlockFactory.GetBlockById(biome.SurfaceBlock));
                            //column.SetMetadata(x, y, z, biome.SurfaceMetadata);

                            // column.SetBlock(x, y - 1, z,  BlockFactory.GetBlockById(biome.SoilBlock));
                            //column.SetMetadata(x, y -1, z, biome.SoilMetadata);
                        }
                        else if (y < height)
                        {
                            column.SetBlock(x, y, z, new Stone());
                        }
                    }


                    column.SetHeight(x, z, (short)height);
                    //}

                    //column.SetBiome(x, z, biomeId);
                }
            }
        }
예제 #3
0
        private void SetBiomeBlocks(ChunkColumn chunk, ChunkLandscape landscape)
        {
            int worldX = chunk.X * 16;
            int worldZ = chunk.Z * 16;

            var coords = new BlockCoordinates(worldX, 0, worldZ);

            for (int x = 0; x < 16; x++)
            {
                coords.X = worldX + x;
                for (int z = 0; z < 16; z++)
                {
                    coords.Z = worldZ + z;

                    var index = NoiseMap.GetIndex(x, z);
                    var river = landscape.River[index];
                    int depth = -1;

                    landscape.Biome[index].Replace(chunk, coords, x, z, depth, this, landscape.Noise, river, landscape.Biome);
                    chunk.biomeId[index] = (byte)landscape.Biome[index].Id;
                }
            }
        }
        private int[] CalculateBiomes(ChunkCoordinates coordinates, ChunkLandscape landscape)
        {
            // var biomes = BiomeProvider.GetBiomes().ToArray();

            int worldX = coordinates.X << 4;
            int worldZ = coordinates.Z << 4;

            float[] weightedBiomes = new float[256];
            var     biomeData      = new int[SampleArraySize * SampleArraySize];

            for (int x = -SampleSize; x < SampleSize + 5; x++)
            {
                for (int z = -SampleSize; z < SampleSize + 5; z++)
                {
                    var xx = worldX + ((x * 8f));
                    var zz = worldZ + ((z * 8f));

                    var temp = TemperatureNoise.GetValue(xx, zz);

                    //Note for self: The temperature noise returns a value between -1 & 1 however we need the value to be between 0 & 2.
                    //We do this by getting the absolute value (0 to 1) and multiplying it by 2.
                    temp = MathF.Abs(temp) * 2f;

                    var rain = MathF.Abs(RainfallNoise.GetValue(xx, zz));

                    if (temp < _lowestTemp)
                    {
                        _lowestTemp = temp;
                    }

                    if (temp > _highestTemp)
                    {
                        _highestTemp = temp;
                    }

                    if (rain < _lowestHumidity)
                    {
                        _lowestHumidity = rain;
                    }

                    if (rain > _highestHumidity)
                    {
                        _highestHumidity = rain;
                    }

                    _totalTemp     += temp;
                    _totalHumidity += rain;
                    _totalLookups++;

                    if (_totalLookups % 1024 == 0)
                    {
                        /*  Console.Clear();
                         *
                         * Console.WriteLine(
                         *    $"Average temperature: {_totalTemp / _totalLookups} Highest: {_highestTemp} Lowest: {_lowestTemp}");
                         *
                         * Console.WriteLine(
                         *    $"Average humidity: {_totalHumidity / _totalLookups} Highest: {_highestHumidity} Lowest: {_lowestHumidity}");
                         *
                         * Console.WriteLine($"Unique biomes: {_uniqueBiomes.Count}");*/
                    }

                    biomeData[(x + SampleSize) * SampleArraySize + (z + SampleSize)] = (BiomeProvider.GetBiome(
                                                                                            (float)temp, (float)rain).Id);
                }
            }

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    int index = NoiseMap.GetIndex(x, z);

                    float totalWeight = 0;
                    for (int mapX = 0; mapX < SampleArraySize; mapX++)
                    {
                        for (int mapZ = 0; mapZ < SampleArraySize; mapZ++)
                        {
                            float weight = _weightings[mapX * SampleArraySize + mapZ][(x << 4) + z];
                            if (weight > 0)
                            {
                                totalWeight += weight;
                                weightedBiomes[biomeData[mapX * SampleArraySize + mapZ]] += weight;
                            }
                        }
                    }

                    // normalize biome weights
                    for (int biomeIndex = 0; biomeIndex < weightedBiomes.Length; biomeIndex++)
                    {
                        weightedBiomes[biomeIndex] /= totalWeight;
                    }

                    // combine mesa biomes
                    // mesaCombiner.adjust(weightedBiomes);
                    landscape.Noise[index] = 0f;

                    float river = TerrainBase.GetRiverStrength(new BlockCoordinates(worldX + x, 0, worldZ + z), this);
                    landscape.River[index] = -river;

                    float maxWeight = 0f;
                    for (int i = 0; i < weightedBiomes.Length; i++)
                    {
                        var value = weightedBiomes[i];

                        if (value > 0f)
                        {
                            var biome = BiomeProvider.GetBiome(i);

                            landscape.Noise[index] += biome.RNoise(
                                this, worldX + x, worldZ + z, value, river + 1f) * value;

                            weightedBiomes[i] = 0f;

                            if (value > maxWeight)
                            {
                                maxWeight = value;
                                landscape.Biome[index] = biome;

                                if (!_uniqueBiomes.Contains(biome.Id))
                                {
                                    _uniqueBiomes.TryAdd(biome.Id);
                                    // Console.WriteLine($"Unique biomes: {uniqueBiomes.Count}");
                                }
                            }
                        }
                    }

                    //landscape.Biome[index] = weightedBiomes.;

                    // landscape.Biome[index] = BiomeProvider.GetBiome(i);
                    //landscape.Biome[index] = BiomeProvider.GetBiome();
                }
            }

            return(biomeData);
        }
예제 #5
0
        private int[] CalculateBiomes(ChunkCoordinates coordinates, ChunkLandscape landscape)
        {
            int worldX = coordinates.X * 16;
            int worldZ = coordinates.Z * 16;

            float[] weightedBiomes = new float[256];
            var     biomeData      = new int[SampleArraySize * SampleArraySize];

            for (int x = -SampleSize; x < SampleSize + 5; x++)
            {
                for (int z = -SampleSize; z < SampleSize + 5; z++)
                {
                    var temp = TemperatureNoise.GetValue(worldX + ((x * 8)), worldZ + ((z * 8)));
                    var rain = RainfallNoise.GetValue(worldX + ((x * 8)), worldZ + ((z * 8)));

                    biomeData[(x + SampleSize) * SampleArraySize + (z + SampleSize)] = (BiomeProvider.GetBiome((float)temp, (float)rain).Id);
                }
            }

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    int index = NoiseMap.GetIndex(x, z);

                    float totalWeight = 0;
                    for (int mapX = 0; mapX < SampleArraySize; mapX++)
                    {
                        for (int mapZ = 0; mapZ < SampleArraySize; mapZ++)
                        {
                            float weight = _weightings[mapX * SampleArraySize + mapZ][x * 16 + z];
                            if (weight > 0)
                            {
                                totalWeight += weight;
                                weightedBiomes[biomeData[mapX * SampleArraySize + mapZ]] += weight;
                            }
                        }
                    }

                    // normalize biome weights
                    for (int biomeIndex = 0; biomeIndex < weightedBiomes.Length; biomeIndex++)
                    {
                        weightedBiomes[biomeIndex] /= totalWeight;
                    }

                    // combine mesa biomes
                    // mesaCombiner.adjust(weightedBiomes);

                    landscape.Noise[index] = 0f;

                    float river = TerrainBase.GetRiverStrength(new BlockCoordinates(worldX + x, 0, worldZ + z), this);
                    landscape.River[index] = -river;

                    for (int i = 0; i < 256; i++)
                    {
                        var value = weightedBiomes[i];
                        if (value > 0f)
                        {
                            var biome = BiomeProvider.GetBiome(i);
                            landscape.Noise[index] += biome.RNoise(this, worldX + x, worldZ + z, value, river + 1f) * value;
                            landscape.Biome[index]  = biome;
                            // 0 for the next column
                            weightedBiomes[i] = 0f;
                        }
                    }

                    // landscape.Biome[index] = BiomeProvider.GetBiome(i);
                    //landscape.Biome[index] = BiomeProvider.GetBiome();
                }
            }

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    BlockCoordinates pos = new BlockCoordinates(worldX + (x - 7) * 8 + 4, 0, worldZ + (z - 7) * 8 + 4);
                    //  landscape.Biome[x * 16 + z] = BiomeProvider.GetBiome(pos.X, pos.Z);
                }
            }

            return(biomeData);
        }