Example #1
0
        private void drawingSurface_Draw(object sender, DrawEventArgs e)
        {
            _graphicsDevice.Clear(new Color(0f, 0f, 0f, 1.0f));
            _graphicsDevice.RasterizerState = RasterizerState.CullNone;
            if (_simulation != null)
            {
                while (_simulation.CancelationToken)
                {
                    Thread.Sleep(_memoryTimerInterval);
                }
                if (!_simulation.CancelationToken)
                {
                    _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                    for (int i = 0; i < _simulation.Cells.Count; i++)
                    {
                        if (i < _simulation.Cells.Count)
                        {
                            var c = _simulation.Cells[i];
                            drawCell(c);
                        }
                    }
                    _simulation.ExecuteNextCycle();
                    _spriteBatch.End();
                }
            }

            //VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[]{
            //    new VertexPositionNormalTexture(new Vector3(-1, -1, 0),
            //        Vector3.Forward,Vector2.Zero),
            //    new VertexPositionNormalTexture(new Vector3(0, 1, 0),
            //        Vector3.Forward,Vector2.Zero),
            //    new VertexPositionNormalTexture(new Vector3(1, -1, 0),
            //        Vector3.Forward,Vector2.Zero)};

            //VertexBuffer vb = new VertexBuffer(g, VertexPositionNormalTexture.VertexDeclaration,
            //              vertices.Length, BufferUsage.WriteOnly);
            //vb.SetData(0, vertices, 0, vertices.Length, 0);
            //g.SetVertexBuffer(vb);

            //BasicEffect basicEffect = new BasicEffect(g);
            //basicEffect.EnableDefaultLighting();
            //basicEffect.LightingEnabled = true;

            //basicEffect.Texture = new Texture2D(g, 1, 1, false, SurfaceFormat.Color);
            //basicEffect.Texture.SetData<Color>(new Color[1] { new Color(1f, 0, 0) });
            //basicEffect.TextureEnabled = true;

            //basicEffect.World = Matrix.CreateRotationY((float)e.TotalTime.TotalSeconds * 2);
            //basicEffect.View = Matrix.CreateLookAt(new Vector3(0, 0, 5.0f),
            //              Vector3.Zero, Vector3.Up);
            //basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView
            //              (0.85f, aspectRatio, 0.01f, 1000.0f);

            //basicEffect.CurrentTechnique.Passes[0].Apply();
            //g.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
            e.InvalidateSurface();
        }
Example #2
0
 public void Start()
 {
     StartTime = DateTime.Now;
     _realtimeSimulation.Paused = false;
     while (!_realtimeSimulation.IsCompleted)
     {
         var cycle = new Cycle {
             StartTime = DateTime.Now, Index = _realtimeSimulation.Cycle
         };
         cycle.Cells = _realtimeSimulation.Cells.Select(x => x.Clone()).ToList();
         _realtimeSimulation.ExecuteNextCycle();
         cycle.EndTime = DateTime.Now;
         Cycles.Add(cycle);
         if (OnNextCycle != null)
         {
             OnNextCycle(this, new EventArgs());
         }
     }
     completed();
 }