Exemplo n.º 1
0
        void RunRenderWindow()
        {
            bool winStarted = false;
            Task winthread  = new Task(() =>
            {
                win        = new RenderWindow(renderer, midifile, settings);
                winStarted = true;
                win.Run();
            });

            winthread.Start();
            SpinWait.SpinUntil(() => winStarted);
            long      time      = 0;
            int       nc        = -1;
            long      maxRam    = 0;
            long      avgRam    = 0;
            long      ramSample = 0;
            Stopwatch timewatch = new Stopwatch();

            timewatch.Start();
            try
            {
                while ((midifile.ParseUpTo(time += (long)(win.tempoFrameStep * 10)) || nc != 0) && settings.running)
                {
                    SpinWait.SpinUntil(() => midifile.currentSyncTime < win.midiTime + win.lastDeltaTimeOnScreen + (long)(win.tempoFrameStep * 10) || !settings.running);
                    if (!settings.running)
                    {
                        break;
                    }
                    nc = 0;
                    Note n;
                    lock (midifile.globalDisplayNotes)
                    {
                        var    i          = midifile.globalDisplayNotes.Iterate();
                        double cutoffTime = 0;
                        cutoffTime = win.midiTime;
                        while (i.MoveNext(out n))
                        {
                            if (n.delete)
                            {
                                i.Remove();
                            }
                            else
                            {
                                nc++;
                            }
                        }
                    }
                    try
                    {
                        Console.WriteLine(
                            Math.Round((double)time / midifile.maxTrackTime * 10000) / 100 + "%\tNotes loaded: " + nc +
                            "\tNotes drawn: " + renderer.renderer.LastNoteCount +
                            "\tRender FPS: " + Math.Round(settings.liveFps) + "        "
                            );
                    }
                    catch
                    {
                    }
                    long ram = Process.GetCurrentProcess().PrivateMemorySize64;
                    if (maxRam < ram)
                    {
                        maxRam = ram;
                    }
                    avgRam = (long)((double)avgRam * ramSample + ram) / (ramSample + 1);
                    ramSample++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred while opeining render window. Please try again.\n\n" + ex.Message + "\n" + ex.StackTrace);
                settings.running = false;
            }
            winthread.GetAwaiter().GetResult();
            settings.running = false;
            midifile.Reset();
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine(
                "Finished render\nRAM usage (Private bytes)\nPeak: " + Math.Round((double)maxRam / 1000 / 1000 / 1000 * 100) / 100 +
                "GB\nAvg: " + Math.Round((double)avgRam / 1000 / 1000 / 1000 * 100) / 100 +
                "GB\nMinutes to render: " + Math.Round((double)timewatch.ElapsedMilliseconds / 1000 / 60 * 100) / 100);
            Console.ResetColor();
            Dispatcher.Invoke(() =>
            {
                Resources["notRendering"]  = true;
                Resources["notPreviewing"] = true;
            });
        }