TpsDebugChart.java

net.minecraft.client.gui.components.debugchart.TpsDebugChart

信息

  • 全限定名:net.minecraft.client.gui.components.debugchart.TpsDebugChart
  • 类型:public class
  • 包:net.minecraft.client.gui.components.debugchart
  • 源码路径:src/main/java/net/minecraft/client/gui/components/debugchart/TpsDebugChart.java
  • 起始行号:L14
  • 继承:AbstractDebugChart
  • 职责:

    TODO

字段/常量

  • TICK_METHOD_COLOR

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L15
    • 说明:

      TODO

  • TASK_COLOR

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L16
    • 说明:

      TODO

  • OTHER_COLOR

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L17
    • 说明:

      TODO

  • msptSupplier

    • 类型: Supplier<Float>
    • 修饰符: private final
    • 源码定位: L18
    • 说明:

      TODO

内部类/嵌套类型

构造器

public TpsDebugChart(Font font, SampleStorage sampleStorage, Supplier<Float> msptSupplier) @ L20

  • 构造器名:TpsDebugChart
  • 源码定位:L20
  • 修饰符:public

参数:

  • font: Font
  • sampleStorage: SampleStorage
  • msptSupplier: Supplier

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected void extractAdditionalLinesAndLabels(GuiGraphicsExtractor graphics, int left, int width, int bottom) @ L25

  • 方法名:extractAdditionalLinesAndLabels
  • 源码定位:L25
  • 返回类型:void
  • 修饰符:protected

参数:

  • graphics: GuiGraphicsExtractor
  • left: int
  • width: int
  • bottom: int

说明:

TODO

protected void extractAdditionalSampleBars(GuiGraphicsExtractor graphics, int bottom, int currentX, int sampleIndex) @ L31

  • 方法名:extractAdditionalSampleBars
  • 源码定位:L31
  • 返回类型:void
  • 修饰符:protected

参数:

  • graphics: GuiGraphicsExtractor
  • bottom: int
  • currentX: int
  • sampleIndex: int

说明:

TODO

protected long getValueForAggregation(int sampleIndex) @ L47

  • 方法名:getValueForAggregation
  • 源码定位:L47
  • 返回类型:long
  • 修饰符:protected

参数:

  • sampleIndex: int

说明:

TODO

protected String toDisplayString(double nanos) @ L52

  • 方法名:toDisplayString
  • 源码定位:L52
  • 返回类型:String
  • 修饰符:protected

参数:

  • nanos: double

说明:

TODO

protected int getSampleHeight(double nanos) @ L57

  • 方法名:getSampleHeight
  • 源码定位:L57
  • 返回类型:int
  • 修饰符:protected

参数:

  • nanos: double

说明:

TODO

protected int getSampleColor(long nanos) @ L62

  • 方法名:getSampleColor
  • 源码定位:L62
  • 返回类型:int
  • 修饰符:protected

参数:

  • nanos: long

说明:

TODO

private static double toMilliseconds(double nanos) @ L68

  • 方法名:toMilliseconds
  • 源码定位:L68
  • 返回类型:double
  • 修饰符:private static

参数:

  • nanos: double

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class TpsDebugChart extends AbstractDebugChart {
    private static final int TICK_METHOD_COLOR = -6745839;
    private static final int TASK_COLOR = -4548257;
    private static final int OTHER_COLOR = -10547572;
    private final Supplier<Float> msptSupplier;
 
    public TpsDebugChart(Font font, SampleStorage sampleStorage, Supplier<Float> msptSupplier) {
        super(font, sampleStorage);
        this.msptSupplier = msptSupplier;
    }
 
    @Override
    protected void extractAdditionalLinesAndLabels(GuiGraphicsExtractor graphics, int left, int width, int bottom) {
        float tps = (float)TimeUtil.MILLISECONDS_PER_SECOND / this.msptSupplier.get();
        this.extractStringWithShade(graphics, String.format(Locale.ROOT, "%.1f TPS", tps), left + 1, bottom - 60 + 1);
    }
 
    @Override
    protected void extractAdditionalSampleBars(GuiGraphicsExtractor graphics, int bottom, int currentX, int sampleIndex) {
        long tickMethodTime = this.sampleStorage.get(sampleIndex, TpsDebugDimensions.TICK_SERVER_METHOD.ordinal());
        int tickMethodHeight = this.getSampleHeight(tickMethodTime);
        graphics.fill(currentX, bottom - tickMethodHeight, currentX + 1, bottom, -6745839);
        long tasksTime = this.sampleStorage.get(sampleIndex, TpsDebugDimensions.SCHEDULED_TASKS.ordinal());
        int tasksHeight = this.getSampleHeight(tasksTime);
        graphics.fill(currentX, bottom - tickMethodHeight - tasksHeight, currentX + 1, bottom - tickMethodHeight, -4548257);
        long otherTime = this.sampleStorage.get(sampleIndex)
            - this.sampleStorage.get(sampleIndex, TpsDebugDimensions.IDLE.ordinal())
            - tickMethodTime
            - tasksTime;
        int otherHeight = this.getSampleHeight(otherTime);
        graphics.fill(currentX, bottom - otherHeight - tasksHeight - tickMethodHeight, currentX + 1, bottom - tasksHeight - tickMethodHeight, -10547572);
    }
 
    @Override
    protected long getValueForAggregation(int sampleIndex) {
        return this.sampleStorage.get(sampleIndex) - this.sampleStorage.get(sampleIndex, TpsDebugDimensions.IDLE.ordinal());
    }
 
    @Override
    protected String toDisplayString(double nanos) {
        return String.format(Locale.ROOT, "%d ms", (int)Math.round(toMilliseconds(nanos)));
    }
 
    @Override
    protected int getSampleHeight(double nanos) {
        return (int)Math.round(toMilliseconds(nanos) * 60.0 / this.msptSupplier.get().floatValue());
    }
 
    @Override
    protected int getSampleColor(long nanos) {
        float mspt = this.msptSupplier.get();
        return this.getSampleColor(toMilliseconds(nanos), mspt, -16711936, mspt * 1.125, -256, mspt * 1.25, -65536);
    }
 
    private static double toMilliseconds(double nanos) {
        return nanos / 1000000.0;
    }
}

引用的其他类