2025-11-24 22:52:51 +03:00

109 lines
4.5 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* org.jspecify.annotations.Nullable
*/
package net.minecraft.client.gui.components.debugchart;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.List;
import java.util.Locale;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.util.profiling.ProfileResults;
import net.minecraft.util.profiling.ResultField;
import org.jspecify.annotations.Nullable;
public class ProfilerPieChart {
public static final int RADIUS = 105;
public static final int PIE_CHART_THICKNESS = 10;
private static final int MARGIN = 5;
private final Font font;
private @Nullable ProfileResults profilerPieChartResults;
private String profilerTreePath = "root";
private int bottomOffset = 0;
public ProfilerPieChart(Font font) {
this.font = font;
}
public void setPieChartResults(@Nullable ProfileResults results) {
this.profilerPieChartResults = results;
}
public void setBottomOffset(int bottomOffset) {
this.bottomOffset = bottomOffset;
}
public void render(GuiGraphics graphics) {
if (this.profilerPieChartResults == null) {
return;
}
List<ResultField> list = this.profilerPieChartResults.getTimes(this.profilerTreePath);
ResultField rootNode = list.removeFirst();
int chartCenterX = graphics.guiWidth() - 105 - 10;
int left = chartCenterX - 105;
int right = chartCenterX + 105;
int textUnderChartHeight = list.size() * this.font.lineHeight;
int bottom = graphics.guiHeight() - this.bottomOffset - 5;
int textStartY = bottom - textUnderChartHeight;
int chartHalfSizeY = 62;
int chartCenterY = textStartY - 62 - 5;
graphics.fill(left - 5, chartCenterY - 62 - 5, right + 5, bottom + 5, -1873784752);
graphics.submitProfilerChartRenderState(list, left, chartCenterY - 62 + 10, right, chartCenterY + 62);
DecimalFormat format = new DecimalFormat("##0.00", DecimalFormatSymbols.getInstance(Locale.ROOT));
String rootNodeName = ProfileResults.demanglePath(rootNode.name);
Object topText = "";
if (!"unspecified".equals(rootNodeName)) {
topText = (String)topText + "[0] ";
}
topText = rootNodeName.isEmpty() ? (String)topText + "ROOT " : (String)topText + rootNodeName + " ";
int col = -1;
int topTextY = chartCenterY - 62;
graphics.drawString(this.font, (String)topText, left, topTextY, -1);
topText = format.format(rootNode.globalPercentage) + "%";
graphics.drawString(this.font, (String)topText, right - this.font.width((String)topText), topTextY, -1);
for (int i = 0; i < list.size(); ++i) {
ResultField result = list.get(i);
StringBuilder string = new StringBuilder();
if ("unspecified".equals(result.name)) {
string.append("[?] ");
} else {
string.append("[").append(i + 1).append("] ");
}
Object msg = string.append(result.name).toString();
int textY = textStartY + i * this.font.lineHeight;
graphics.drawString(this.font, (String)msg, left, textY, result.getColor());
msg = format.format(result.percentage) + "%";
graphics.drawString(this.font, (String)msg, right - 50 - this.font.width((String)msg), textY, result.getColor());
msg = format.format(result.globalPercentage) + "%";
graphics.drawString(this.font, (String)msg, right - this.font.width((String)msg), textY, result.getColor());
}
}
public void profilerPieChartKeyPress(int key) {
if (this.profilerPieChartResults == null) {
return;
}
List<ResultField> list = this.profilerPieChartResults.getTimes(this.profilerTreePath);
if (list.isEmpty()) {
return;
}
ResultField node = list.remove(0);
if (key == 0) {
int pos;
if (!node.name.isEmpty() && (pos = this.profilerTreePath.lastIndexOf(30)) >= 0) {
this.profilerTreePath = this.profilerTreePath.substring(0, pos);
}
} else if (--key < list.size() && !"unspecified".equals(list.get((int)key).name)) {
if (!this.profilerTreePath.isEmpty()) {
this.profilerTreePath = this.profilerTreePath + "\u001e";
}
this.profilerTreePath = this.profilerTreePath + list.get((int)key).name;
}
}
}