Ejemplo n.º 1
0
        public static void Generate()
        {
            //while (true)
            //    Test.Show(RenderNoiseBmp(500, 500));
            while (true)
            {
            int seed = Environment.TickCount;
            seed = new Random().Next(8, 16777216); // 16777216 = 8^8
            DateTime asdf = System.DateTime.Now;
            seed = asdf.Millisecond + asdf.Minute + asdf.Hour + asdf.Year;
            Random rand = new Random(seed);
            PolygonMap map = new PolygonMap(rand.Next());

            Console.Out.WriteLine("Generating map...");
            map.Generate(Size * 15);

            Console.Out.WriteLine("Creating terrain...");
            var dat = CreateTerrain(rand.Next(), map);

            Console.Out.WriteLine("Computing biomes...");
            new Biome(rand.Next(), map).ComputeBiomes(dat);

            new TerrainDisplay(dat).ShowDialog();
            //Test.Show(RenderMoistBmp(dat));
            //Test.Show(RenderEvalBmp(dat));

            map = null;
            dat = null;
            GC.WaitForFullGCComplete(-1);
            GC.Collect();
            }
        }
Ejemplo n.º 2
0
        public static void Generate()
        {
            //while (true)
            //    Test.Show(RenderNoiseBmp(500, 500));
            while (true)
            {
                var seed = Environment.TickCount;
                seed = new Random().Next(8, 16777216); // 16777216 = 8^8
                var asdf = DateTime.Now;
                seed = asdf.Millisecond + asdf.Minute + asdf.Hour + asdf.Year;
                var rand = new Random(seed);
                var map  = new PolygonMap(rand.Next());

                Console.Out.WriteLine("Generating map...");
                map.Generate(Size * 15);

                Console.Out.WriteLine("Creating terrain...");
                var dat = CreateTerrain(rand.Next(), map);

                Console.Out.WriteLine("Computing biomes...");
                new Biome(rand.Next(), map).ComputeBiomes(dat);


                new TerrainDisplay(dat).ShowDialog();
                //Test.Show(RenderMoistBmp(dat));
                //Test.Show(RenderEvalBmp(dat));

                map = null;
                dat = null;
                GC.WaitForFullGCComplete(-1);
                GC.Collect();
            }
        }
Ejemplo n.º 3
0
        public static void Generate()
        {
            while (true)
            {
                int seed = Environment.TickCount;
                seed = new Random().Next(8, 1); // 16777216 = 8^8
                DateTime asdf = DateTime.Now;
                seed = asdf.Millisecond + asdf.Minute + asdf.Hour + asdf.Year;
                Random     rand = new Random(seed);
                PolygonMap map  = new PolygonMap(rand.Next());

                Console.Out.WriteLine("Generating map...");
                map.Generate(Size);

                Console.Out.WriteLine("Creating terrain...");
                TerrainTile[,] dat = CreateTerrain(rand.Next(), map);

                Console.Out.WriteLine("Computing biomes...");
                new Biome(rand.Next(), map).ComputeBiomes(dat);


                new TerrainDisplay(dat).ShowDialog();

                map = null;
                dat = null;
                GC.WaitForFullGCComplete(-1);
                GC.Collect();
            }
        }
Ejemplo n.º 4
0
        public static void Generate()
        {
            //while (true)
            //    Test.Show(RenderNoiseBmp(500, 500));
            while (true)
            {
                int seed = Environment.TickCount;
                //seed = 21409625;
                seed = 14727484;
                var rand = new Random(seed);
                var map  = new PolygonMap(rand.Next());
                map.Generate(Size * 15);

                TerrainTile[,] dat = CreateTerrain(rand.Next(), map);
                new Biome(rand.Next(), map).ComputeBiomes(dat);

                new TerrainDisplay(dat).ShowDialog();
                //Test.Show(RenderMoistBmp(dat));
                //Test.Show(RenderEvalBmp(dat));

                map = null;
                dat = null;
                GC.WaitForFullGCComplete(-1);
                GC.Collect();
            }
        }
Ejemplo n.º 5
0
        public static void Generate()
        {
            //while (true)
            //    Test.Show(RenderNoiseBmp(500, 500));
            while (true)
            {
                int seed = Environment.TickCount;
                //seed = 21409625;
                seed = 14727484;
                Random rand = new Random(seed);
                PolygonMap map = new PolygonMap(rand.Next());
                map.Generate(Size * 15);

                var dat = CreateTerrain(rand.Next(), map);
                new Biome(rand.Next(), map).ComputeBiomes(dat);
                new TerrainDisplay(dat).ShowDialog();
                //Test.Show(RenderColorBmp(dat));
                //Test.Show(RenderTerrainBmp(dat));
                //Test.Show(RenderMoistBmp(dat));
                //Test.Show(RenderEvalBmp(dat));

                map = null;
                dat = null;
                GC.WaitForFullGCComplete(-1);
                GC.Collect();
            }
        }
Ejemplo n.º 6
0
        public static void Generate()
        {
            //while (true)
            //    Test.Show(RenderNoiseBmp(500, 500));
            while (true)
            {
                int seed = Environment.TickCount;
                //seed = 15465515;
                seed = 21409625;
                Random     rand = new Random(seed);
                PolygonMap map  = new PolygonMap(rand.Next());
                map.Generate(Size * 6);

                var dat = CreateTerrain(rand.Next(), map);
                new Biome(rand.Next(), map).ComputeBiomes(dat);
                Test.Show(RenderColorBmp(dat));
                Test.Show(RenderTerrainBmp(dat));
                Test.Show(RenderMoistBmp(dat));
                Test.Show(RenderEvalBmp(dat));

                map = null;
                dat = null;
                GC.WaitForFullGCComplete(-1);
                GC.Collect();
            }
        }
Ejemplo n.º 7
0
 public Biome(int seed, PolygonMap map)
 {
     rand     = new Random(seed);
     this.map = map;
 }
Ejemplo n.º 8
0
 public MapFeatures(PolygonMap map, int seed)
 {
     this.map = map;
     rand     = new Random(seed);
 }
Ejemplo n.º 9
0
        private static TerrainTile[,] CreateTerrain(int seed, PolygonMap map)
        {
            var rasterizer = new Rasterizer <TerrainTile>(Size, Size);

            //Set all to ocean
            rasterizer.Clear(new TerrainTile
            {
                PolygonId = -1,
                Elevation = 0,
                Moisture  = 1,
                TileId    = TileTypes.DeepWater,
                TileObj   = null
            });
            //Render lands poly
            foreach (var poly in map.Polygons.Where(_ => !_.IsWater))
            {
                uint color = 0x00ffffff;
                color |= (uint)(poly.DistanceToCoast * 255) << 24;
                rasterizer.FillPolygon(
                    poly.Nodes.SelectMany(_ =>
                {
                    return(new[]
                    {
                        (_.X + 1) / 2 * Size,
                        (_.Y + 1) / 2 * Size
                    });
                }).Concat(new[]
                {
                    (poly.Nodes[0].X + 1) / 2 * Size,
                    (poly.Nodes[0].Y + 1) / 2 * Size
                }).ToArray(),
                    new TerrainTile
                {
                    PolygonId = poly.Id,
                    Elevation = (float)poly.DistanceToCoast,
                    Moisture  = -1,
                    TileId    = TileTypes.Grass,
                    TileObj   = null
                });
            }
            var fea = new MapFeatures(map, seed);
            //Render roads
            var roads = fea.GenerateRoads();

            foreach (var i in roads)
            {
                rasterizer.DrawClosedCurve(i.SelectMany(_ => new[]
                {
                    (_.X + 1) / 2 * Size, (_.Y + 1) / 2 * Size
                }).ToArray(),
                                           1, t =>
                {
                    t.TileId = TileTypes.Road;
                    return(t);
                }, 3);
            }
            //Render waters poly
            foreach (var poly in map.Polygons.Where(_ => _.IsWater))
            {
                var tile = new TerrainTile
                {
                    PolygonId = poly.Id,
                    Elevation = (float)poly.DistanceToCoast,
                    TileObj   = null
                };
                if (poly.IsCoast)
                {
                    tile.TileId   = TileTypes.MovingWater;
                    tile.Moisture = 0;
                }
                else
                {
                    tile.TileId   = TileTypes.DeepWater;
                    tile.Moisture = 1;
                }
                rasterizer.FillPolygon(
                    poly.Nodes.SelectMany(_ =>
                {
                    return(new[]
                    {
                        (_.X + 1) / 2 * Size,
                        (_.Y + 1) / 2 * Size
                    });
                }).Concat(new[]
                {
                    (poly.Nodes[0].X + 1) / 2 * Size,
                    (poly.Nodes[0].Y + 1) / 2 * Size
                }).ToArray(), tile);
            }
            //Render rivers
            var rivers = fea.GenerateRivers();
            var edges  = new Dictionary <Tuple <MapNode, MapNode>, int>();

            foreach (var i in rivers)
            {
                for (var j = 1; j < i.Length; j++)
                {
                    var edge = new Tuple <MapNode, MapNode>(i[j - 1], i[j]);
                    int count;
                    if (edges.TryGetValue(edge, out count))
                    {
                        count++;
                    }
                    else
                    {
                        count = 1;
                    }
                    edges[edge] = count;
                }
            }
            foreach (var i in edges)
            {
                i.Key.Item1.IsWater    = true;
                i.Key.Item1.RiverValue = i.Value + 1;
                i.Key.Item2.IsWater    = true;
                i.Key.Item2.RiverValue = i.Value + 1;
                rasterizer.DrawLineBresenham(
                    (i.Key.Item1.X + 1) / 2 * Size, (i.Key.Item1.Y + 1) / 2 * Size,
                    (i.Key.Item2.X + 1) / 2 * Size, (i.Key.Item2.Y + 1) / 2 * Size,
                    t =>
                {
                    t.TileId    = TileTypes.Water;
                    t.Elevation = (float)(i.Key.Item1.DistanceToCoast + i.Key.Item2.DistanceToCoast) / 2;
                    t.Moisture  = 1;
                    return(t);
                }, 3 * Math.Min(2, i.Value));
            }

            return(rasterizer.Buffer);
        }
Ejemplo n.º 10
0
 public Biome(int seed, PolygonMap map)
 {
     rand = new Random(seed);
     this.map = map;
 }
Ejemplo n.º 11
0
        static TerrainTile[,] CreateTerrain(int seed, PolygonMap map)
        {
            Rasterizer<TerrainTile> rasterizer = new Rasterizer<TerrainTile>(Size, Size);
            //Set all to ocean
            rasterizer.Clear(new TerrainTile()
            {
                PolygonId = -1,
                Elevation = 0,
                Moisture = 1,
                TileId = TileTypes.DeepWater,
                TileObj = null
            });
            //Render lands poly
            foreach (var poly in map.Polygons.Where(_ => !_.IsWater))
            {
                uint color = 0x00ffffff;
                color |= (uint)(poly.DistanceToCoast * 255) << 24;
                rasterizer.FillPolygon(
                    poly.Nodes.SelectMany(_ =>
                    {
                        return new[]{ (_.X + 1) / 2 * Size,
                                      (_.Y + 1) / 2 * Size};
                    }).Concat(new[]{ (poly.Nodes[0].X + 1) / 2 * Size,
                                     (poly.Nodes[0].Y + 1) / 2 * Size}).ToArray(),
                    new TerrainTile()
                    {
                        PolygonId = poly.Id,
                        Elevation = (float)poly.DistanceToCoast,
                        Moisture = -1,
                        TileId = TileTypes.Grass,
                        TileObj = null
                    });
            }
            MapFeatures fea = new MapFeatures(map, seed);
            //Render roads
            var roads = fea.GenerateRoads();
            foreach (var i in roads)
            {
                rasterizer.DrawClosedCurve(i.SelectMany(_ => new[] {
                    (_.X + 1) / 2 * Size, (_.Y + 1) / 2 * Size }).ToArray(),
                    1, t =>
                    {
                        t.TileId = TileTypes.Road;
                        return t;
                    }, 3);
            }
            //Render waters poly
            foreach (var poly in map.Polygons.Where(_ => _.IsWater))
            {
                var tile = new TerrainTile()
                {
                    PolygonId = poly.Id,
                    Elevation = (float)poly.DistanceToCoast,
                    TileObj = null
                };
                if (poly.IsCoast)
                {
                    tile.TileId = TileTypes.MovingWater;
                    tile.Moisture = 0;
                }
                else
                {
                    tile.TileId = TileTypes.DeepWater;
                    tile.Moisture = 1;
                }
                rasterizer.FillPolygon(
                    poly.Nodes.SelectMany(_ =>
                    {
                        return new[]{ (_.X + 1) / 2 * Size,
                                      (_.Y + 1) / 2 * Size};
                    }).Concat(new[]{ (poly.Nodes[0].X + 1) / 2 * Size,
                                     (poly.Nodes[0].Y + 1) / 2 * Size}).ToArray(), tile);
            }
            //Render rivers
            var rivers = fea.GenerateRivers();
            Dictionary<Tuple<MapNode, MapNode>, int> edges = new Dictionary<Tuple<MapNode, MapNode>, int>();
            foreach (var i in rivers)
            {
                for (int j = 1; j < i.Length; j++)
                {
                    Tuple<MapNode, MapNode> edge = new Tuple<MapNode, MapNode>(i[j - 1], i[j]);
                    int count;
                    if (edges.TryGetValue(edge, out count))
                        count++;
                    else
                        count = 1;
                    edges[edge] = count;
                }
            }
            foreach (var i in edges)
            {
                i.Key.Item1.IsWater = true;
                i.Key.Item1.RiverValue = i.Value + 1;
                i.Key.Item2.IsWater = true;
                i.Key.Item2.RiverValue = i.Value + 1;
                rasterizer.DrawLineBresenham(
                    (i.Key.Item1.X + 1) / 2 * Size, (i.Key.Item1.Y + 1) / 2 * Size,
                    (i.Key.Item2.X + 1) / 2 * Size, (i.Key.Item2.Y + 1) / 2 * Size,
                    t =>
                    {
                        t.TileId = TileTypes.Water;
                        t.Elevation = (float)(i.Key.Item1.DistanceToCoast + i.Key.Item2.DistanceToCoast) / 2;
                        t.Moisture = 1;
                        return t;
                    }, 3 * Math.Min(2, i.Value));
            }

            return rasterizer.Buffer;
        }
Ejemplo n.º 12
0
 public MapFeatures(PolygonMap map, int seed)
 {
     this.map = map;
     rand = new Random(seed);
 }