Esempio n. 1
0
        protected override void LoadContent()
        {
            this.pixelSize = ConvertPixelToClip(Vector2.One);

            this.effect = new MultiCellEffect(this.Device);

            this.simulation = new LimitedSimulation(width, width);
            this.stopwatch  = new Stopwatch();

            // Create a random grid
            var rd = new Random();

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < width; y++)
                {
                    int index = (y * width) + x;
                    if (rd.Next(0, 10) > 5)
                    {
                        this.simulation.Grid.SetCell(x, y, true);
                    }
                }
            }

            // Create graphcis partition (grid to graphics)
            this.partition = new Partition(Device, width * width);
            UpdateSimulationGraphics();

            // TODO: Matrix
            contantBuffer = new Buffer(Device, Utilities.SizeOf <Vector4>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            Form.MouseDown += Form_MouseDown;
            Form.MouseMove += Form_MouseMove;
            Form.KeyDown   += Form_KeyDown;
        }
        public void still_life_works()
        {
            int[] points     = { 2, 2, 2, 3, 3, 2, 3, 3 };
            var   simulation = new LimitedSimulation(10, 10);

            for (int i = 0; i < points.Length - 1; i += 2)
            {
                simulation.Grid.SetCell(points[i], points[i + 1], true);
            }

            for (int i = 0; i < points.Length - 1; i += 2)
            {
                Assert.True(simulation.Grid.GetCell(points[i], points[i + 1]));
            }

            simulation.Step();

            for (int i = 0; i < points.Length - 1; i += 2)
            {
                Assert.True(simulation.Grid.GetCell(points[i], points[i + 1]));
            }
        }