Пример #1
0
        public OverworldTerrain(OverworldTerrainSettings ots, bool isUnitTest = false)
        {
            settings = ots;

            ocean     = new OceanTerrain(ots);
            plains    = new PlainsTerrain(ots);
            hills     = new HillsTerrain(ots);
            badlands  = new BadlandsTerrain(ots);
            mountains = new MountainsTerrain(ots);
            rivers    = new RiverTerrain(ots);

            humidity    = new HumidityNoise(ots);
            temperature = new TemperatureNoise(ots);
            terrain     = new TerrainNoise(ots);

            cave = new CavesCarver(ots);

            // Scale Point multiplies input values by the scaling factors.
            // Used to stretch or shrink the terrain horizontally.
            var scaled = GetScaledModuleOutput(MergedLandOceanRivers());
            //var scaled = GetScaledModuleOutput(LandOceanSelector());
            //var scaled = GetScaledModuleOutput(temperature.RiverSelector);

            // Scale bias scales the verical output (usually -1.0 to +1.0) to
            // Minecraft values. If MinElev is 40 (leaving room for caves under oceans)
            // and MaxElev is 168, a value of -1 becomes 40, and a value of 1 becomes 168.
            var biased = new ScaleBias
            {
                Scale   = (settings.MaxElev - settings.MinElev) / 2.0,
                Bias    = settings.MinElev + ((settings.MaxElev - settings.MinElev) / 2.0) - 44,
                Source0 = scaled
            };

            Result = isUnitTest ? scaled : biased;
        }
Пример #2
0
        // I/F
        public float GetTemperature(int x, int z)
        {
            float xf = x * inverseSizeX;
            float zf = z * inverseSizeZ;

            return(MathExtension.Saturate(TemperatureNoise.Sample(xf, 0, zf)));
        }
Пример #3
0
        private static void GenerateTemperature(PolygonMapGenerator PMG)
        {
            float            poleTemperature        = -12f;
            float            equatorTemperature     = 35f;
            float            temperatureModifyRange = 15f;
            TemperatureNoise noise = new TemperatureNoise(poleTemperature, equatorTemperature, temperatureModifyRange);

            foreach (GraphPolygon polygon in PMG.Polygons)
            {
                float noiseValue = noise.GetValue(polygon.CenterPoi.x, polygon.CenterPoi.y, PMG.GenerationSettings);
                polygon.Temperature = (int)noiseValue;
            }

            //if (Visualize) NoiseTester.DisplayNoise(noise, NoiseTester.TemperaturePlane, MapData, poleTemperature - temperatureModifyRange, equatorTemperature + temperatureModifyRange);
        }
Пример #4
0
    private static void GenerateTemperature()
    {
        float            poleTemperature        = -12f;
        float            equatorTemperature     = 35f;
        float            temperatureModifyRange = 15f;
        TemperatureNoise noise = new TemperatureNoise(poleTemperature, equatorTemperature, temperatureModifyRange);

        foreach (TileData td in MapData.Tiles)
        {
            float noiseValue = noise.GetValue(td.Position.x, td.Position.z, MapData);
            td.Temperature = (int)noiseValue;
        }

        if (Visualize)
        {
            NoiseTester.DisplayNoise(noise, NoiseTester.TemperaturePlane, MapData, poleTemperature - temperatureModifyRange, equatorTemperature + temperatureModifyRange);
        }
    }
        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);
        }
Пример #6
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);
        }