FpsDebugChart .java

net.minecraft.client.gui.components.debugchart.FpsDebugChart (class, 50 lines): members: CHART_TOP_FPS, CHART_TOP_VALUE, extractAdditionalLinesAndLabels.

net.minecraft.client.gui.components.debugchartclass50 linesclientextends AbstractDebugChart1.8 KB

API Surface (4)

void extractAdditionalLinesAndLabels(final GuiGraphicsExtractor graphics, final int left, final int width, final int bottom)
String toDisplayString(final double nanos)
int getSampleHeight(final double nanos)
int getSampleColor(final long nanos)

Fields & Constants (2)

CHART_TOP_FPS
CHART_TOP_VALUE

String literals (2)

"30 fps"
"60 fps"

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

FpsDebugChart.java50 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.components.debugchart;
2
3
import java.util.Locale;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.client.Minecraft;
7
import net.minecraft.client.gui.Font;
8
import net.minecraft.client.gui.GuiGraphicsExtractor;
9
import net.minecraft.util.debugchart.SampleStorage;
10
11
@Environment(EnvType.CLIENT)
12
public class FpsDebugChart extends AbstractDebugChart {
13
	private static final int CHART_TOP_FPS = 30;
14
	private static final double CHART_TOP_VALUE = 33.333333333333336;
15
16
	public FpsDebugChart(final Font font, final SampleStorage sampleStorage) {
17
		super(font, sampleStorage);
18
	}
19
20
	@Override
21
	protected void extractAdditionalLinesAndLabels(final GuiGraphicsExtractor graphics, final int left, final int width, final int bottom) {
22
		this.extractStringWithShade(graphics, "30 fps", left + 1, bottom - 60 + 1);
23
		this.extractStringWithShade(graphics, "60 fps", left + 1, bottom - 30 + 1);
24
		graphics.horizontalLine(left, left + width - 1, bottom - 30, -1);
25
		int framerateLimit = Minecraft.getInstance().options.framerateLimit().get();
26
		if (framerateLimit > 0 && framerateLimit <= 250) {
27
			graphics.horizontalLine(left, left + width - 1, bottom - this.getSampleHeight(1.0E9 / framerateLimit) - 1, -16711681);
28
		}
29
	}
30
31
	@Override
32
	protected String toDisplayString(final double nanos) {
33
		return String.format(Locale.ROOT, "%d ms", (int)Math.round(toMilliseconds(nanos)));
34
	}
35
36
	@Override
37
	protected int getSampleHeight(final double nanos) {
38
		return (int)Math.round(toMilliseconds(nanos) * 60.0 / 33.333333333333336);
39
	}
40
41
	@Override
42
	protected int getSampleColor(final long nanos) {
43
		return this.getSampleColor(toMilliseconds(nanos), 0.0, -16711936, 28.0, -256, 56.0, -65536);
44
	}
45
46
	private static double toMilliseconds(final double nanos) {
47
		return nanos / 1000000.0;
48
	}
49
}
50

Decompiled Minecraft 26.3 source of FpsDebugChart (net/minecraft/client/gui/components/debugchart/FpsDebugChart.java) with Mojang official mappings, stored verbatim on the site.