internal static void DrawEntries(Rect rect, Panel_Graph instance, int entries, float aliasing) { if (Event.current.type != EventType.Repaint) { return; } var xIncrement = rect.width / (entries - 1.0f); var timeCutoff = 0.0f; var callsCutoff = 0.0f; if (aliasing != 0) { timeCutoff = instance.calls.max / rect.height / aliasing; callsCutoff = instance.times.max / rect.height / aliasing; } int i = 1, timesIndex = 0, callsIndex = 0; visibleMin = instance.times.entries[timesIndex]; for (; i < entries; i++) { if (instance.calls.visible) { if (Mathf.Abs(instance.calls.entries[callsIndex] - instance.calls.entries[i]) > callsCutoff || i == entries - 1) // We need to draw a line, enough of a difference { DrawLine(instance.calls, callsIndex, i, rect.height, xIncrement, Settings.callsColour); callsIndex = i; } } if (!instance.times.visible) { continue; } if (Mathf.Abs(instance.times.entries[timesIndex] - instance.times.entries[i]) > timeCutoff || i == entries - 1) { var point = DrawLine(instance.times, timesIndex, i, rect.height, xIncrement, Settings.timeColour); if (instance.times.entries[i] < visibleMin) { visibleMin = instance.times.entries[timesIndex]; } var cheese = new Rect(point.x - (xIncrement * 0.5f), 0, xIncrement, rect.height); if (Mouse.IsOver(cheese)) { SimpleCurveDrawer.DrawPoint(point); hoverValStr = $"{instance.times.entries[timesIndex]}ms {instance.calls.entries[timesIndex]} calls"; } timesIndex = i; } } }
public static void DoGraph(Rect position) { ResetRange++; if (ResetRange >= 500) { ResetRange = 0; WindowMax = 0; } Text.Font = GameFont.Small; var settings = position.TopPartPixels(30f); position = position.BottomPartPixels(position.height - 30f); Widgets.DrawBoxSolid(position, Analyzer.Settings.GraphCol); GUI.color = Color.grey; Widgets.DrawBox(position, 2); GUI.color = Color.white; if (!Analyzer.Profiles.ContainsKey(key)) { return; } var prof = Analyzer.Profiles[key]; if (prof.History.times.Length <= 0) { return; } var mescou = prof.History.times.Length; if (mescou > entryCount) { mescou = entryCount; } var gap = position.width / mescou; var car = settings.RightPartPixels(200f); car.x -= 15; entryCount = (int)Widgets.HorizontalSlider(car, entryCount, 10, 2000, true, string.Intern($"{entryCount} Entries")); car = new Rect(car.xMax + 5, car.y + 2, 10, 10); Widgets.DrawBoxSolid(car, Analyzer.Settings.LineCol); if (Widgets.ButtonInvisible(car, true)) { if (Find.WindowStack.WindowOfType <colourPicker>() != null) { Find.WindowStack.RemoveWindowsOfType(typeof(colourPicker)); } else { var cp = new colourPicker { Setcol = () => Analyzer.Settings.LineCol = colourPicker.CurrentCol }; cp.SetColor(Analyzer.Settings.LineCol); Find.WindowStack.Add(cp); } } car.y += 12; Widgets.DrawBoxSolid(car, Analyzer.Settings.GraphCol); if (Widgets.ButtonInvisible(car, true)) { if (Find.WindowStack.WindowOfType <colourPicker>() != null) { Find.WindowStack.RemoveWindowsOfType(typeof(colourPicker)); } else { var cp = new colourPicker { Setcol = () => Analyzer.Settings.GraphCol = colourPicker.CurrentCol }; cp.SetColor(Analyzer.Settings.GraphCol); Find.WindowStack.Add(cp); } } if (Analyzer.Settings.AdvancedMode) { var memr = settings.LeftPartPixels(20f); if (Widgets.ButtonImageFitted(memr, mem, ShowMem ? Color.white : Color.grey)) { ShowMem = !ShowMem; } GUI.color = Color.white; TooltipHandler.TipRegion(memr, "Toggle garbage tracking, approximation of total garbage produced by the selected log"); memr.x = memr.xMax; memr.width = 300f; if (ShowMem) { Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(memr, totalBytesStr); } } Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(settings, hoverValStr); Text.Anchor = TextAnchor.UpperLeft; maxBytes = 0; minBytes = 0; var LastMax = max; max = 0; GUI.BeginGroup(position); position = position.AtZero(); for (var i = 0; i < mescou; i++) { var bytes = prof.History.mem[i]; var TM = prof.History.times[i]; if (i == 0) { minBytes = bytes; maxBytes = bytes; max = TM; } if (bytes < minBytes) { minBytes = bytes; } if (bytes > maxBytes) { maxBytes = bytes; } if (TM > max) { max = TM; } } if (max > WindowMax) { WindowMax = (float)max; } var DoHover = false; for (var i = 0; i < mescou; i++) { var bytes = prof.History.mem[i]; var TM = prof.History.times[i]; var y = GenMath.LerpDoubleClamped(0, WindowMax, position.height, position.y, (float)TM); var MEMy = GenMath.LerpDoubleClamped(minBytes, maxBytes, position.height, position.y, bytes); var screenPoint = new Vector2(position.xMax - gap * i, y); var MEMscreenPoint = new Vector2(position.xMax - gap * i, MEMy); if (i != 0) { Widgets.DrawLine(last, screenPoint, Analyzer.Settings.LineCol, 1f); if (ShowMem) { Widgets.DrawLine(lastMEM, MEMscreenPoint, Color.grey, 2f); } var vag = new Rect(screenPoint.x - gap / 2f, position.y, gap, position.height); //if (Widgets.ButtonInvisible(vag)) //{ // Log.Warning(prof.History.stack[i]); // Find.WindowStack.Windows.Add(new StackWindow { stkRef = prof.History.stack[i] }); //} if (Mouse.IsOver(vag)) { DoHover = true; if (i != hoverVal) { hoverVal = i; hoverValStr = $"{TM} {prof.History.hits[i]} calls"; } SimpleCurveDrawer.DrawPoint(screenPoint); } } last = screenPoint; lastMEM = MEMscreenPoint; } if (LastMax != max) { MaxStr = $"Max {max}ms"; } if (LASTtotalBytesStr < prof.BytesUsed) { LASTtotalBytesStr = prof.BytesUsed; totalBytesStr = $"Mem {(long)(prof.BytesUsed / (long)1024)} Kb"; } var LogMaxY = GenMath.LerpDoubleClamped(0, WindowMax, position.height, position.y, (float)max); var crunt = position; crunt.y = LogMaxY; Widgets.Label(crunt, MaxStr); Widgets.DrawLine(new Vector2(position.x, LogMaxY), new Vector2(position.xMax, LogMaxY), Color.red, 1f); last = Vector2.zero; GUI.EndGroup(); }