private static void GenerateBiomeMap(int chunks)
        {
            int    finished    = 0;
            Bitmap bitmap      = new Bitmap(chunks * 16, chunks * 16);
            Bitmap heightmap   = new Bitmap(chunks * 16, chunks * 16);
            Bitmap chunkHeight = new Bitmap(chunks * 16, chunks * 16);

            while (finished < chunks * chunks)
            {
                if (Finished.TryDequeue(out ChunkColumn column))
                {
                    for (int cx = 0; cx < 16; cx++)
                    {
                        var rx = (column.X * 16) + cx;
                        for (int cz = 0; cz < 16; cz++)
                        {
                            var rz = (column.Z * 16) + cz;

                            var biome = BiomeUtils.GetBiomeById(column.GetBiome(cx, cz));
                            var temp  = (int)Math.Max(0,
                                                      Math.Min(255, (255 * MathUtils.ConvertRange(-1f, 2f, 0f, 1f, biome.Temperature))));
                            var humid = (int)Math.Max(32,
                                                      Math.Min(255, (255 * biome.Downfall)));

                            bitmap.SetPixel(rx, rz, Color.FromArgb(humid, temp, 0, 255 - temp));

                            int height = column.GetHeight(cx, cz);

                            chunkHeight.SetPixel(rx, rz, Color.FromArgb(height, height, height));

                            height = (int)Math.Max(0,
                                                   Math.Min(255,
                                                            (255 * MathUtils.ConvertRange(-2f, 2f, 0f, 1f,
                                                                                          ((biome.MinHeight + biome.MaxHeight) / 2f)))));

                            heightmap.SetPixel(rx, rz, Color.FromArgb(height, height, height));
                        }
                    }

                    Imaged++;
                    finished++;
                }
                else
                {
                    Thread.Sleep(50);
                }
            }

            bitmap.Save("heatmap.png", ImageFormat.Png);
            heightmap.Save("height.png", ImageFormat.Png);
            chunkHeight.Save("chunkHeight.png", ImageFormat.Png);
        }
Beispiel #2
0
        public OverworldGenerator()
        {
            BiomeUtils.FixMinMaxHeight();

            //GeneratorPreset = JsonConvert.DeserializeObject<WorldGeneratorPreset>("{\"coordinateScale\":450.0,\"heightScale\":1.0,\"lowerLimitScale\":1450.0,\"upperLimitScale\":1450.0,\"depthNoiseScaleX\":200.0,\"depthNoiseScaleZ\":200.0,\"depthNoiseScaleExponent\":0.5,\"mainNoiseScaleX\":1800.0,\"mainNoiseScaleY\":5000.0,\"mainNoiseScaleZ\":1800.0,\"baseSize\":9.275,\"stretchY\":4.005,\"biomeDepthWeight\":1.105,\"biomeDepthOffset\":0.01,\"biomeScaleWeight\":4.0,\"biomeScaleOffset\":0.01,\"seaLevel\":63,\"useCaves\":true,\"useDungeons\":true,\"dungeonChance\":10,\"useStrongholds\":true,\"useVillages\":true,\"useMineShafts\":true,\"useTemples\":true,\"useMonuments\":true,\"useRavines\":true,\"useWaterLakes\":true,\"waterLakeChance\":100,\"useLavaLakes\":true,\"lavaLakeChance\":100,\"useLavaOceans\":false,\"fixedBiome\":-1,\"biomeSize\":5,\"riverSize\":5,\"dirtSize\":33,\"dirtCount\":12,\"dirtMinHeight\":0,\"dirtMaxHeight\":256,\"gravelSize\":33,\"gravelCount\":12,\"gravelMinHeight\":0,\"gravelMaxHeight\":256,\"graniteSize\":33,\"graniteCount\":12,\"graniteMinHeight\":0,\"graniteMaxHeight\":255,\"dioriteSize\":33,\"dioriteCount\":12,\"dioriteMinHeight\":0,\"dioriteMaxHeight\":255,\"andesiteSize\":33,\"andesiteCount\":12,\"andesiteMinHeight\":0,\"andesiteMaxHeight\":255,\"coalSize\":17,\"coalCount\":25,\"coalMinHeight\":0,\"coalMaxHeight\":255,\"ironSize\":9,\"ironCount\":25,\"ironMinHeight\":0,\"ironMaxHeight\":255,\"goldSize\":9,\"goldCount\":8,\"goldMinHeight\":0,\"goldMaxHeight\":255,\"redstoneSize\":8,\"redstoneCount\":10,\"redstoneMinHeight\":0,\"redstoneMaxHeight\":255,\"diamondSize\":8,\"diamondCount\":8,\"diamondMinHeight\":0,\"diamondMaxHeight\":255,\"lapisSize\":7,\"lapisCount\":2,\"lapisCenterHeight\":125,\"lapisSpread\":100}");
            var generatorPreset = JsonConvert.DeserializeObject <WorldGeneratorPreset>("{\"coordinateScale\":175.0,\"heightScale\":75.0,\"lowerLimitScale\":512.0,\"upperLimitScale\":512.0,\"depthNoiseScaleX\":200.0,\"depthNoiseScaleZ\":200.0,\"depthNoiseScaleExponent\":0.5,\"mainNoiseScaleX\":165.0,\"mainNoiseScaleY\":106.61267,\"mainNoiseScaleZ\":165.0,\"baseSize\":8.267606,\"stretchY\":13.387607,\"biomeDepthWeight\":1.2,\"biomeDepthOffset\":0.2,\"biomeScaleWeight\":3.4084506,\"biomeScaleOffset\":0.0,\"seaLevel\":63,\"useCaves\":true,\"useDungeons\":true,\"dungeonChance\":7,\"useStrongholds\":true,\"useVillages\":true,\"useMineShafts\":true,\"useTemples\":true,\"useMonuments\":true,\"useRavines\":true,\"useWaterLakes\":true,\"waterLakeChance\":49,\"useLavaLakes\":true,\"lavaLakeChance\":80,\"useLavaOceans\":false,\"fixedBiome\":-1,\"biomeSize\":8,\"riverSize\":5,\"dirtSize\":33,\"dirtCount\":10,\"dirtMinHeight\":0,\"dirtMaxHeight\":256,\"gravelSize\":33,\"gravelCount\":8,\"gravelMinHeight\":0,\"gravelMaxHeight\":256,\"graniteSize\":33,\"graniteCount\":10,\"graniteMinHeight\":0,\"graniteMaxHeight\":80,\"dioriteSize\":33,\"dioriteCount\":10,\"dioriteMinHeight\":0,\"dioriteMaxHeight\":80,\"andesiteSize\":33,\"andesiteCount\":10,\"andesiteMinHeight\":0,\"andesiteMaxHeight\":80,\"coalSize\":17,\"coalCount\":20,\"coalMinHeight\":0,\"coalMaxHeight\":128,\"ironSize\":9,\"ironCount\":20,\"ironMinHeight\":0,\"ironMaxHeight\":64,\"goldSize\":9,\"goldCount\":2,\"goldMinHeight\":0,\"goldMaxHeight\":32,\"redstoneSize\":8,\"redstoneCount\":8,\"redstoneMinHeight\":0,\"redstoneMaxHeight\":16,\"diamondSize\":8,\"diamondCount\":1,\"diamondMinHeight\":0,\"diamondMaxHeight\":16,\"lapisSize\":7,\"lapisCount\":1,\"lapisCenterHeight\":16,\"lapisSpread\":16}");

            // GeneratorPreset = JsonConvert.DeserializeObject<WorldGeneratorPreset>(
            //      "{\"useCaves\":true,\"useStrongholds\":true,\"useVillages\":true,\"useMineShafts\":true,\"useTemples\":true,\"useRavines\":true,\"useMonuments\":true,\"useMansions\":true,\"useLavaOceans\":false,\"useWaterLakes\":true,\"useLavaLakes\":true,\"useDungeons\":true,\"fixedBiome\":-3,\"biomeSize\":4,\"seaLevel\":63,\"riverSize\":4,\"waterLakeChance\":4,\"lavaLakeChance\":80,\"dungeonChance\":8,\"dirtSize\":33,\"dirtCount\":10,\"dirtMinHeight\":0,\"dirtMaxHeight\":255,\"gravelSize\":33,\"gravelCount\":8,\"gravelMinHeight\":0,\"gravelMaxHeight\":255,\"graniteSize\":33,\"graniteCount\":10,\"graniteMinHeight\":0,\"graniteMaxHeight\":80,\"dioriteSize\":33,\"dioriteCount\":10,\"dioriteMinHeight\":0,\"dioriteMaxHeight\":80,\"andesiteSize\":33,\"andesiteCount\":10,\"andesiteMinHeight\":0,\"andesiteMaxHeight\":80,\"coalSize\":17,\"coalCount\":20,\"coalMinHeight\":0,\"coalMaxHeight\":128,\"ironSize\":9,\"ironCount\":20,\"ironMinHeight\":0,\"ironMaxHeight\":64,\"goldSize\":9,\"goldCount\":2,\"goldMinHeight\":0,\"goldMaxHeight\":32,\"redstoneSize\":8,\"redstoneCount\":8,\"redstoneMinHeight\":0,\"redstoneMaxHeight\":16,\"diamondSize\":8,\"diamondCount\":1,\"diamondMinHeight\":0,\"diamondMaxHeight\":16,\"lapisSize\":7,\"lapisCount\":1,\"lapisMinHeight\":0,\"lapisMaxHeight\":32,\"coordinateScale\":684,\"heightScale\":684,\"mainNoiseScaleX\":80,\"mainNoiseScaleY\":160,\"mainNoiseScaleZ\":80,\"depthNoiseScaleX\":200,\"depthNoiseScaleZ\":200,\"depthNoiseScaleExponent\":0.5,\"biomeDepthWeight\":1,\"biomeDepthOffset\":0,\"biomeScaleWeight\":1,\"biomeScaleOffset\":1,\"lowerLimitScale\":512,\"upperLimitScale\":512,\"baseSize\":8.5,\"stretchY\":12,\"lapisCenterHeight\":16,\"lapisSpread\":16}");
            WaterLevel = generatorPreset.SeaLevel;

            var seed = "test-world".GetHashCode();

            Seed          = seed;
            NoiseProvider = new NoiseProvider(generatorPreset, seed);
        }
        private static Task GenerateHeightmap(ChunkColumn[] columns, int chunks, bool chunkHeight)
        {
            return(Task.Run(() =>
            {
                Bitmap bitmap = new Bitmap(chunks * 16, chunks * 16);
                for (int x = 0; x < chunks; x++)
                {
                    for (int z = 0; z < chunks; z++)
                    {
                        ChunkColumn column = columns[(x * chunks) + z];
                        for (int cx = 0; cx < 16; cx++)
                        {
                            var rx = (x * 16) + cx;
                            for (int cz = 0; cz < 16; cz++)
                            {
                                var rz = (z * 16) + cz;

                                //  var height = column.GetHeight(cx, cz);
                                //  var temp = (int) Math.Max((byte)0,
                                //     Math.Min((byte)255, height));

                                var height = 0;

                                if (!chunkHeight)
                                {
                                    height = column.GetHeight(cx, cz);
                                }
                                else
                                {
                                    var biome = BiomeUtils.GetBiomeById(column.GetBiome(cx, cz));
                                    height = (int)Math.Max(0,
                                                           Math.Min(255, (255 * MathUtils.ConvertRange(-2f, 2f, 0f, 1f, ((biome.MinHeight + biome.MaxHeight) / 2f)))));
                                }

                                bitmap.SetPixel(rx, rz, Color.FromArgb(height, height, height));
                            }
                        }
                    }
                }

                bitmap.Save(chunkHeight ? "chunkHeight.png" : "height.png", ImageFormat.Png);
            }));
        }
Beispiel #4
0
        public BiomeBase GetBiome(float x, float z, float height)
        {
            // x /= CoordinateScale;
            //  z /= CoordinateScale;

            var mX = x;                                                                                    // + BiomeModifierX.GetValue(x, z);
            var mZ = z;                                                                                    // + BiomeModifierZ.GetValue(x, z);

            var temp = MathUtils.ConvertRange(-1f, 1f, -1f, 2f, NoiseProvider.TempNoise.GetValue(mX, mZ)); // _tempNoise.GetValue(mX, mZ);
            var rain = MathUtils.ConvertRange(-1f, 1f, 0, 1f, NoiseProvider.RainNoise.GetValue(mX, mZ));   //MathUtils.ConvertRange(0f, 1f, 0f, 2f, _rainNoise.GetValue(mX, mZ));// _rainNoise.GetValue(mX, mZ);

            var terrainHeight = NoiseProvider.TerrainNoise.GetValue(mX, mZ);

            //     terrainHeight = MathUtils.ConvertRange(-1f, 1f, 0f, 1f, terrainHeight);

            /* return BiomeUtils.Biomes
             *   .OrderBy(biome =>
             *       MathF.Abs((MathUtils.Lerp(biome.MinHeight, biome.MaxHeight, terrainHeight) - height)))
             *   .ThenBy(biome => BiomeUtils.GetSquaredDistance(biome, temp, rain))
             *   //.ThenBy(bb => Math.Abs(bb.Temperature - temp)).ThenBy(bb => Math.Abs(bb.Downfall - rain))
             *   .FirstOrDefault();*/

            return(BiomeUtils.Biomes
                   .OrderBy(bb => Math.Abs(bb.Temperature - temp)).ThenBy(bb => Math.Abs(bb.Downfall - rain))
                   .ThenBy(biome => MathF.Abs((MathUtils.Lerp(biome.MinHeight, biome.MaxHeight, terrainHeight) - height)))
                   //.ThenBy(bb => Math.Abs(bb.Temperature - temp)).ThenBy(bb => Math.Abs(bb.Downfall - rain))
                   .FirstOrDefault());

            //var upper = _upperLimit.GetValue(mX, mZ);
            //var lower = _lowerLimit.GetValue(mX, mZ);

            /*var ordered = BiomeUtils.GetOrderedBiomes(temp, rain, height).Take(3).OrderBy(biome =>
             * {
             *  var avg = MathUtils.Lerp(biome.MinHeight, biome.MaxHeight, MathUtils.ConvertRange(-1f, 1f, -2f, 2f, _terrainNoise.GetValue(mX, mZ)));
             *  return MathF.Abs((avg - height) * (avg - height));
             * }).FirstOrDefault();//.FirstOrDefault(xx => xx.MinHeight >= lower && xx.MaxHeight <= upper);
             * return ordered;*/
            //if (temp < -1f) temp = -(temp%1);
            // if (rain < 0) rain = -rain;

            return(BiomeUtils.GetBiome(temp, rain));
        }