ProfilerPieChart.java
net.minecraft.client.gui.components.debugchart.ProfilerPieChart
信息
- 全限定名:net.minecraft.client.gui.components.debugchart.ProfilerPieChart
- 类型:public class
- 包:net.minecraft.client.gui.components.debugchart
- 源码路径:src/main/java/net/minecraft/client/gui/components/debugchart/ProfilerPieChart.java
- 起始行号:L17
- 职责:
TODO
字段/常量
-
RADIUS- 类型:
int - 修饰符:
public static final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
PIE_CHART_THICKNESS- 类型:
int - 修饰符:
public static final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
PERCENTAGE_FORMAT- 类型:
DecimalFormat - 修饰符:
private static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
MARGIN- 类型:
int - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
SUBSEQUENT_LINES_INDENT- 类型:
int - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
font- 类型:
Font - 修饰符:
private final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
profilerPieChartResults- 类型:
ProfileResults - 修饰符:
private - 源码定位:
L25 - 说明:
TODO
- 类型:
-
profilerTreePath- 类型:
String - 修饰符:
private - 源码定位:
L26 - 说明:
TODO
- 类型:
-
bottomOffset- 类型:
int - 修饰符:
private - 源码定位:
L27 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ProfilerPieChart(Font font) @ L29
- 构造器名:ProfilerPieChart
- 源码定位:L29
- 修饰符:public
参数:
- font: Font
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void setPieChartResults(ProfileResults results) @ L33
- 方法名:setPieChartResults
- 源码定位:L33
- 返回类型:void
- 修饰符:public
参数:
- results: ProfileResults
说明:
TODO
public void setBottomOffset(int bottomOffset) @ L37
- 方法名:setBottomOffset
- 源码定位:L37
- 返回类型:void
- 修饰符:public
参数:
- bottomOffset: int
说明:
TODO
public void extractRenderState(GuiGraphicsExtractor graphics) @ L41
- 方法名:extractRenderState
- 源码定位:L41
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
说明:
TODO
private List<String> splitNodeName(String nodeName, int firstLineMaxWidth, int maxWidth) @ L97
- 方法名:splitNodeName
- 源码定位:L97
- 返回类型:List
- 修饰符:private
参数:
- nodeName: String
- firstLineMaxWidth: int
- maxWidth: int
说明:
TODO
public void profilerPieChartKeyPress(int key) @ L129
- 方法名:profilerPieChartKeyPress
- 源码定位:L129
- 返回类型:void
- 修饰符:public
参数:
- key: int
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class ProfilerPieChart {
public static final int RADIUS = 105;
public static final int PIE_CHART_THICKNESS = 10;
private static final DecimalFormat PERCENTAGE_FORMAT = new DecimalFormat("##0.00", DecimalFormatSymbols.getInstance(Locale.ROOT));
private static final int MARGIN = 5;
private static final int WIDTH = 260;
private static final int SUBSEQUENT_LINES_INDENT = 10;
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 extractRenderState(GuiGraphicsExtractor graphics) {
if (this.profilerPieChartResults != null) {
List<ResultField> list = this.profilerPieChartResults.getTimes(this.profilerTreePath);
ResultField currentNode = list.removeFirst();
int chartCenterX = graphics.guiWidth() - 130 - 10;
int left = chartCenterX - 130;
int right = chartCenterX + 130;
int textUnderChartHeight = list.size() * 9;
int bottom = graphics.guiHeight() - this.bottomOffset - 5;
int textStartY = bottom - textUnderChartHeight;
int chartHalfSizeY = 62;
int chartCenterY = textStartY - 62 - 5;
String globalPercentage = PERCENTAGE_FORMAT.format(currentNode.globalPercentage) + "%";
int globalPercentageWidth = this.font.width(globalPercentage);
int zeroPrefixWidth = this.font.width("[0] ");
int topTextMaxWidth = right - globalPercentageWidth - 5 - left - zeroPrefixWidth;
String currentNodeName = ProfileResults.demanglePath(currentNode.name);
List<String> currentNodeNameLines = this.splitNodeName(currentNodeName, topTextMaxWidth, topTextMaxWidth - 10);
int currentNodeNameTop = chartCenterY - 62 - (currentNodeNameLines.size() - 1) * 9;
graphics.fill(left - 5, currentNodeNameTop - 5, right + 5, bottom + 5, -1873784752);
graphics.profilerChart(list, left, chartCenterY - 62 + 10, right, chartCenterY + 62);
String firstLineText = "";
if (!"unspecified".equals(currentNodeName) && !"root".equals(currentNodeName)) {
firstLineText = firstLineText + "[0] ";
}
firstLineText = firstLineText + currentNodeNameLines.getFirst();
int col = -1;
graphics.text(this.font, firstLineText, left, currentNodeNameTop, -1);
for (int i = 1; i < currentNodeNameLines.size(); i++) {
graphics.text(this.font, currentNodeNameLines.get(i), left + 10 + zeroPrefixWidth, currentNodeNameTop + i * 9, -1);
}
graphics.text(this.font, globalPercentage, right - globalPercentageWidth, currentNodeNameTop, -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("] ");
}
String msg = string.append(result.name).toString();
int textY = textStartY + i * 9;
graphics.text(this.font, msg, left, textY, result.getColor());
msg = PERCENTAGE_FORMAT.format(result.percentage) + "%";
graphics.text(this.font, msg, right - 50 - this.font.width(msg), textY, result.getColor());
msg = PERCENTAGE_FORMAT.format(result.globalPercentage) + "%";
graphics.text(this.font, msg, right - this.font.width(msg), textY, result.getColor());
}
}
}
private List<String> splitNodeName(String nodeName, int firstLineMaxWidth, int maxWidth) {
String[] nodeNameSplit = nodeName.split("\\.");
List<String> lines = new ArrayList<>();
String currentLine = "";
int nameIndex = 0;
while (nameIndex < nodeNameSplit.length) {
String currentName = nodeNameSplit[nameIndex];
String currentNameWithPeriod = (nameIndex != 0 ? "." : "") + currentName;
String newLine = currentLine + currentNameWithPeriod;
int newWidth = this.font.width(newLine);
if (newWidth > (!lines.isEmpty() ? maxWidth : firstLineMaxWidth)) {
if (currentLine.isEmpty()) {
lines.add(currentNameWithPeriod);
nameIndex++;
} else {
lines.add(currentLine);
currentLine = "";
}
} else {
currentLine = newLine;
nameIndex++;
}
}
if (!currentLine.isEmpty()) {
lines.add(currentLine);
}
return lines;
}
public void profilerPieChartKeyPress(int key) {
if (this.profilerPieChartResults != null) {
List<ResultField> list = this.profilerPieChartResults.getTimes(this.profilerTreePath);
if (!list.isEmpty()) {
ResultField node = list.remove(0);
if (key == 0) {
if (!node.name.isEmpty()) {
int pos = this.profilerTreePath.lastIndexOf(30);
if (pos >= 0) {
this.profilerTreePath = this.profilerTreePath.substring(0, pos);
}
}
} else {
key--;
if (key < list.size() && !"unspecified".equals(list.get(key).name)) {
if (!this.profilerTreePath.isEmpty()) {
this.profilerTreePath = this.profilerTreePath + "\u001e";
}
this.profilerTreePath = this.profilerTreePath + list.get(key).name;
}
}
}
}
}
}引用的其他类
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/方法调用 - 关联成员:
ProfileResults.demanglePath()
- 引用位置: