コード例 #1
0
        private void Benchmark()
        {
            Running = true;

            var pic = new BWPicture(Width, Height);

            Generation = 0;

            switch (CurrentMode)
            {
            case "Zufällig":
            {
                pic.GenerateRandomPicture();
                break;
            }

            case "Diamant":
            {
                pic.GenerateDiamantPicture();
                break;
            }

            default:
            {
                break;
            }
            }

            GoLInstance = new GameOfLifeCore(pic);

            string report = GoLInstance.Benchmark();

            System.Windows.MessageBox.Show(report, "Benchmark Result", System.Windows.MessageBoxButton.OK);

            Running = false;
        }
コード例 #2
0
        public void StartStopButton()
        {
            if (Running)
            {
                cts.Cancel();
                demo?.Wait();
                updateFPS?.Wait();

                picsRendered = 0;
                NotifyPropertyChanged(nameof(FPS));
                cts = new CancellationTokenSource();

                Running = false;
            }
            else
            {
                var pic = new BWPicture(Width, Height);
                Generation = 0;

                switch (CurrentMode)
                {
                case "Zufällig":
                {
                    pic.GenerateRandomPicture();
                    break;
                }

                case "Diamant":
                {
                    pic.GenerateDiamantPicture();
                    break;
                }

                default:
                {
                    break;
                }
                }

                GoLInstance = new GameOfLifeCore(pic);

                Picture = GoLInstance.CurrentGeneration;

                updateFPS = Task.Run(() =>
                {
                    while (!cts.IsCancellationRequested)
                    {
                        NotifyPropertyChanged(nameof(FPS));
                        Thread.Sleep(TimeSpan.FromSeconds(1));
                    }
                }, cts.Token);

                demo = Task.Run(() =>
                {
                    bool first = true;
                    do
                    {
                        if (first)
                        {
                            GoLInstance.BeginnGeneration();
                            first = false;
                        }
                        else
                        {
                            GoLInstance.UpdateGeneration();
                        }
                        Picture = GoLInstance.CurrentGeneration;
                        //Thread.Sleep(TimeSpan.FromMilliseconds(10));
                    }while (!cts.IsCancellationRequested);
                }, cts.Token);

                Running = true;
            }
        }