Пример #1
0
    // static methods
    public static World Random()
    {
        WorldTile[,] w = new WorldTile[size, size *2];
        bool acceptable = false;
        int  failures   = 0;

        while (!acceptable)
        {
            Program.Log("Generating new world from seed " + Program.seed);
            // generate new world
            // long t_start = DateTime.Now.Ticks;

            /*
             *      for, for					=> 279 ms
             *      Parallel.For, for			=> 100 ms
             *      Parallel.For, Parallel.For	=> 77 ms
             */
            Parallel.For(0, size, y => {
                Parallel.For(0, size * 2, x => {
                    w[y, x] = WorldTile.Random((double)x / size, (double)y / (size - 1));
                });
            });
            // long t_end = DateTime.Now.Ticks;
            // Program.Log(String.Format("took {0} ticks", t_end - t_start));
            // check if valid
            if (Valid(ref w))
            {
                break;
            }
            // otherwise, regen.
            Program.NewSeed();
            failures++;
            if (1000 <= failures)
            {
                Program.Log("No good world in 1,000 tries", 2);
                throw new ArgumentException();
            }
        }
        Program.Log(failures + " failures");
        // create a new thread to continue resource computation in background
        new Task(() => {
            foreach (WorldTile t in w)
            {
                if (t.resource == null)
                {
                    Program.Log("tile has no resource (if this message appears, mocha broke the code!)", 1);
                }
            }
            Program.Log("resource generation complete");
        }).Start();
        // return while thread is running
        return(new World(w));
    }
Пример #2
0
 WorldTile[,] Minimap(int width, int height)
 {
     WorldTile[,] o = new WorldTile[height, width];
     for (int i = 0; i < height; i++)
     {
         for (int j = 0; j < width; j++)
         {
             double rx = x + (double)j / World.size / minimap_scale;
             double ry = y + (double)i / World.size / minimap_scale;
             o[i, j] = WorldTile.Random(rx, ry);
         }
     }
     return(o);
 }
Пример #3
0
        public static void ExportBitmap()
        {
            Bitmap b = new Bitmap(width, height);
            int    percentnotification = 1;

            Program.Log("Exporting...");
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    WorldTile w = WorldTile.Random(2.0 * x / width, (double)y / height);
                    Microsoft.Xna.Framework.Color c = Mappings.Mapping.ColorSatellite(w);
                    b.SetPixel(x, y, Color.FromArgb(c.R, c.G, c.B));
                }
                if (percentnotification / 100.0 <= (double)x / width)
                {
                    Program.LogProgress(percentnotification, 100);
                    percentnotification++;
                }
            }
            b.Save("export/satellite.png");
            Program.Log("Exported satellite view to export/satellite.png");
        }