Beispiel #1
0
        // The core of the application
        private void step()
        {
            frames++;
            generation++;
            myMap map_alt = new myMap(rule,warp, map.getwidth, map.getheight);
            //build using unsafe block, compile with /unsafe
            //Maximum atainable framerate seems to be 64
            //##############################################
            BitmapData bmData = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            int stride = bmData.Stride;
            System.IntPtr Scan0 = bmData.Scan0;
            unsafe
            {
                byte* p = (byte*)(void*)Scan0;
                int nOffset = stride - bitmap.Width * 3;
                for (int y = 0; y < bitmap.Height; ++y)
                {
                    for (int x = 0; x < bitmap.Width; ++x)
                    {
                        if (map.getN(x, y))
                        {
                            map_alt.setPixel(x, y, true);
                            p[0] = p[1] = p[2] = (byte)(0); // there must be a better way
                        }
                        else
                        {
                            map_alt.setPixel(x, y, false);
                            p[0] = p[1] = p[2] = (byte)(255);
                        }
                        p += 3;
                    }
                    p += nOffset;
                }
            }

            bitmap.UnlockBits(bmData);
            //###############################################
            //End unsafe
            // Safe block runs at 50 fps
            /*
            for(int x=0; x<map.getwidth; x++)
            {
                for(int y=0; y<map.getheight; y++)
                {
                    if(map.getN(x,y))
                    {
                        bitmap.SetPixel(x, y, alive);
                        map_alt.setPixel(x,y,true);
                    }
                    else
                    {
                        bitmap.SetPixel(x, y, dead);
                        map_alt.setPixel(x,y,false);
                    }
                }
            }
            */
            // End safe block
            map = map_alt;
            Invalidate();
        }
Beispiel #2
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            scale = 8; // scale of internal map

            mapWidth = bigBox.Width / scale; // Possible precision loss
            mapHeight = bigBox.Height / scale;

            dead = Color.White;     // Global colors for the display.
            alive = Color.Black;
            map = new myMap(rule, warp, mapWidth, mapHeight);
            //#### Internal Loading ####
            System.Reflection.Assembly thisExe;
            thisExe = System.Reflection.Assembly.GetExecutingAssembly();
            BinaryFormatter binaryRead = new BinaryFormatter();
            map = (myMap)binaryRead.Deserialize(    // Loading of interally saved map.
                thisExe.GetManifestResourceStream("WindowsApplication4.Resources.glidergun.yt"));
            //##########################
            map.Rule = rule;
            initialMap = map;
            //bitmap = map.GetBitmap();
            bitmap = new Bitmap(mapWidth, mapHeight);
            rescale();
        }
Beispiel #3
0
 private void start()
 {
     initialMap = map;
     generation = 0;
     tick.Start();
 }
Beispiel #4
0
 private void SaveMap(string filename, myMap map)
 {
     if (filename.ToString().Length > 0)
     {
         Stream streamWrite = File.Create(filename);
         BinaryFormatter binaryWrite = new BinaryFormatter();
         binaryWrite.Serialize(streamWrite, map);
         streamWrite.Close();
     }
 }
Beispiel #5
0
 private void openFileDialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
 {
     map = LoadMap(openFileDialog.FileName);
     bigBox.Width = map.getwidth * scale;
     bigBox.Height = map.getheight * scale;
     reload();
 }
Beispiel #6
0
 private void menuItem9_Click(object sender, EventArgs e)
 {
     map = initialMap;
     reload();
 }
Beispiel #7
0
 private void menuItem8_Click(object sender, EventArgs e)
 {
     map = new myMap(rule,warp, mapWidth, mapHeight);
     reload();
 }