public static void Render() { var FPS = 0; if (FPSWatch == null) { FPSWatch = Stopwatch.StartNew(); } else { FPSWatch.Stop(); FPS = (int)Math.Floor(1.0f / (float)FPSWatch.Elapsed.TotalSeconds); FPSWatch = Stopwatch.StartNew(); } FPSBuffer[k % 100] = FPS; k++; var avgFPS = (int)FPSBuffer.Average(); if (!SentPerfReport && GameSettings.Default.AllowReporting && avgFPS < 20) { if (FPSFaultTimer != null && FPSFaultTimer.Elapsed.TotalSeconds > 5) { var settings = FileUtils.SerializeBasicJSON <GameSettings.Settings>(GameSettings.Default); var adapter = GameStates.GameState.Game.GraphicsDevice.Adapter; var deviceDetails = String.Format("Num Cores: {4}\nDevice:\nName: {0}\n ID: {1}\n Description: {2}\n Vendor: {3}", adapter.DeviceName, adapter.DeviceId, adapter.Description, adapter.VendorId, Environment.ProcessorCount); var memory = GameStates.PlayState.BytesToString(System.GC.GetTotalMemory(false)); (GameStates.GameState.Game as DwarfGame).TriggerRavenEvent("Low performance detected", String.Format("Average FPS: {0}\nSettings:\n{1}\n{2}\nRAM: {3} {4}", avgFPS, settings, deviceDetails, memory, GameStates.PlayState.BytesToString(Environment.WorkingSet))); SentPerfReport = true; } else if (FPSFaultTimer == null) { FPSFaultTimer = Stopwatch.StartNew(); } } else if (!SentPerfReport && GameSettings.Default.AllowReporting) { FPSFaultTimer = null; } if (DwarfGame.IsConsoleVisible) { PopFrame(); var output = DwarfGame.GetConsoleTile("PERFORMANCE"); output.Lines.Clear(); output.Lines.Add(String.Format("Frame time: {0:000.000}", FPSWatch.Elapsed.TotalMilliseconds)); foreach (var function in Functions) { output.Lines.Add(String.Format("{1:0000} {2:000} {0}\n", function.Value.Name, function.Value.FrameCalls, function.Value.FrameTicks / 1000)); } output.Invalidate(); var fps = DwarfGame.GetConsoleTile("FPS"); if (fps.Children[0] is Gui.Widgets.TextGrid) { fps.RemoveChild(fps.Children[0]); fps.AddChild(new Gui.Widgets.Graph() { AutoLayout = AutoLayout.DockFill, }); fps.Layout(); } var graph = fps.Children[0] as Gui.Widgets.Graph; graph.Values.Add((float)FPSWatch.Elapsed.TotalMilliseconds); while (graph.Values.Count > graph.GraphWidth) { graph.Values.RemoveAt(0); } graph.MinLabelString = String.Format("FPS: {0:000} (avg: {1})", FPS, avgFPS); graph.Invalidate(); } }