| 1 | package net.minecraft.client.gui.components.debugchart;
|
| 2 |
|
| 3 | import java.util.Locale;
|
| 4 | import java.util.function.Supplier;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.gui.Font;
|
| 8 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 9 | import net.minecraft.util.TimeUtil;
|
| 10 | import net.minecraft.util.debugchart.SampleStorage;
|
| 11 | import net.minecraft.util.debugchart.TpsDebugDimensions;
|
| 12 |
|
| 13 | @Environment(EnvType.CLIENT)
|
| 14 | public class TpsDebugChart extends AbstractDebugChart {
|
| 15 | private static final int TICK_METHOD_COLOR = -6745839;
|
| 16 | private static final int TASK_COLOR = -4548257;
|
| 17 | private static final int OTHER_COLOR = -10547572;
|
| 18 | private final Supplier<Float> msptSupplier;
|
| 19 |
|
| 20 | public TpsDebugChart(final Font font, final SampleStorage sampleStorage, final Supplier<Float> msptSupplier) {
|
| 21 | super(font, sampleStorage);
|
| 22 | this.msptSupplier = msptSupplier;
|
| 23 | }
|
| 24 |
|
| 25 | @Override
|
| 26 | protected void extractAdditionalLinesAndLabels(final GuiGraphicsExtractor graphics, final int left, final int width, final int bottom) {
|
| 27 | float tps = (float)TimeUtil.MILLISECONDS_PER_SECOND / this.msptSupplier.get();
|
| 28 | this.extractStringWithShade(graphics, String.format(Locale.ROOT, "%.1f tps", tps), left + 1, bottom - 60 + 1);
|
| 29 | }
|
| 30 |
|
| 31 | @Override
|
| 32 | protected void extractAdditionalSampleBars(final GuiGraphicsExtractor graphics, final int bottom, final int currentX, final int sampleIndex) {
|
| 33 | long tickMethodTime = this.sampleStorage.get(sampleIndex, TpsDebugDimensions.TICK_SERVER_METHOD.ordinal());
|
| 34 | int tickMethodHeight = this.getSampleHeight(tickMethodTime);
|
| 35 | graphics.fill(currentX, bottom - tickMethodHeight, currentX + 1, bottom, -6745839);
|
| 36 | long tasksTime = this.sampleStorage.get(sampleIndex, TpsDebugDimensions.SCHEDULED_TASKS.ordinal());
|
| 37 | int tasksHeight = this.getSampleHeight(tasksTime);
|
| 38 | graphics.fill(currentX, bottom - tickMethodHeight - tasksHeight, currentX + 1, bottom - tickMethodHeight, -4548257);
|
| 39 | long otherTime = this.sampleStorage.get(sampleIndex) - this.sampleStorage.get(sampleIndex, TpsDebugDimensions.IDLE.ordinal()) - tickMethodTime - tasksTime;
|
| 40 | int otherHeight = this.getSampleHeight(otherTime);
|
| 41 | graphics.fill(currentX, bottom - otherHeight - tasksHeight - tickMethodHeight, currentX + 1, bottom - tasksHeight - tickMethodHeight, -10547572);
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | protected long getValueForAggregation(final int sampleIndex) {
|
| 46 | return this.sampleStorage.get(sampleIndex) - this.sampleStorage.get(sampleIndex, TpsDebugDimensions.IDLE.ordinal());
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | protected String toDisplayString(final double nanos) {
|
| 51 | return String.format(Locale.ROOT, "%d ms", (int)Math.round(toMilliseconds(nanos)));
|
| 52 | }
|
| 53 |
|
| 54 | @Override
|
| 55 | protected int getSampleHeight(final double nanos) {
|
| 56 | return (int)Math.round(toMilliseconds(nanos) * 60.0 / this.msptSupplier.get().floatValue());
|
| 57 | }
|
| 58 |
|
| 59 | @Override
|
| 60 | protected int getSampleColor(final long nanos) {
|
| 61 | float mspt = this.msptSupplier.get();
|
| 62 | return this.getSampleColor(toMilliseconds(nanos), mspt, -16711936, mspt * 1.125, -256, mspt * 1.25, -65536);
|
| 63 | }
|
| 64 |
|
| 65 | private static double toMilliseconds(final double nanos) {
|
| 66 | return nanos / 1000000.0;
|
| 67 | }
|
| 68 | }
|
| 69 |
|