AbstractDebugChart.java

net.minecraft.client.gui.components.debugchart.AbstractDebugChart

信息

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

    TODO

字段/常量

  • CHART_HEIGHT

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

      TODO

  • LINE_WIDTH

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

      TODO

  • font

    • 类型: Font
    • 修饰符: protected final
    • 源码定位: L15
    • 说明:

      TODO

  • sampleStorage

    • 类型: SampleStorage
    • 修饰符: protected final
    • 源码定位: L16
    • 说明:

      TODO

内部类/嵌套类型

构造器

protected AbstractDebugChart(Font font, SampleStorage sampleStorage) @ L18

  • 构造器名:AbstractDebugChart
  • 源码定位:L18
  • 修饰符:protected

参数:

  • font: Font
  • sampleStorage: SampleStorage

说明:

TODO

方法

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

public int getWidth(int maxWidth) @ L23

  • 方法名:getWidth
  • 源码定位:L23
  • 返回类型:int
  • 修饰符:public

参数:

  • maxWidth: int

说明:

TODO

public int getFullHeight() @ L27

  • 方法名:getFullHeight
  • 源码定位:L27
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public void extractRenderState(GuiGraphicsExtractor graphics, int left, int width) @ L31

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

参数:

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

说明:

TODO

protected void extractSampleBars(GuiGraphicsExtractor graphics, int bottom, int currentX, int sampleIndex) @ L66

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

参数:

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

说明:

TODO

protected void extractMainSampleBar(GuiGraphicsExtractor graphics, int bottom, int currentX, int sampleIndex) @ L71

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

参数:

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

说明:

TODO

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

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

参数:

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

说明:

TODO

protected long getValueForAggregation(int sampleIndex) @ L81

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

参数:

  • sampleIndex: int

说明:

TODO

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

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

参数:

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

说明:

TODO

protected void extractStringWithShade(GuiGraphicsExtractor graphics, String str, int x, int y) @ L88

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

参数:

  • graphics: GuiGraphicsExtractor
  • str: String
  • x: int
  • y: int

说明:

TODO

protected abstract String toDisplayString(double sample) @ L93

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

参数:

  • sample: double

说明:

TODO

protected abstract int getSampleHeight(double sample) @ L95

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

参数:

  • sample: double

说明:

TODO

protected abstract int getSampleColor(long sample) @ L97

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

参数:

  • sample: long

说明:

TODO

protected int getSampleColor(double sample, double min, int minColor, double mid, int midColor, double max, int maxColor) @ L99

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

参数:

  • sample: double
  • min: double
  • minColor: int
  • mid: double
  • midColor: int
  • max: double
  • maxColor: int

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public abstract class AbstractDebugChart {
    protected static final int CHART_HEIGHT = 60;
    protected static final int LINE_WIDTH = 1;
    protected final Font font;
    protected final SampleStorage sampleStorage;
 
    protected AbstractDebugChart(Font font, SampleStorage sampleStorage) {
        this.font = font;
        this.sampleStorage = sampleStorage;
    }
 
    public int getWidth(int maxWidth) {
        return Math.min(this.sampleStorage.capacity() + 2, maxWidth);
    }
 
    public int getFullHeight() {
        return 60 + 9;
    }
 
    public void extractRenderState(GuiGraphicsExtractor graphics, int left, int width) {
        int bottom = graphics.guiHeight();
        graphics.fill(left, bottom - 60, left + width, bottom, -1873784752);
        long avg = 0L;
        long min = 2147483647L;
        long max = -2147483648L;
        int startIndex = Math.max(0, this.sampleStorage.capacity() - (width - 2));
        int sampleCount = this.sampleStorage.size() - startIndex;
 
        for (int i = 0; i < sampleCount; i++) {
            int currentX = left + i + 1;
            int sampleIndex = startIndex + i;
            long valueForAggregation = this.getValueForAggregation(sampleIndex);
            min = Math.min(min, valueForAggregation);
            max = Math.max(max, valueForAggregation);
            avg += valueForAggregation;
            this.extractSampleBars(graphics, bottom, currentX, sampleIndex);
        }
 
        graphics.horizontalLine(left, left + width - 1, bottom - 60, -1);
        graphics.horizontalLine(left, left + width - 1, bottom - 1, -1);
        graphics.verticalLine(left, bottom - 60, bottom, -1);
        graphics.verticalLine(left + width - 1, bottom - 60, bottom, -1);
        if (sampleCount > 0) {
            String minText = this.toDisplayString(min) + " min";
            String avgText = this.toDisplayString((double)avg / sampleCount) + " avg";
            String maxText = this.toDisplayString(max) + " max";
            graphics.text(this.font, minText, left + 2, bottom - 60 - 9, -2039584);
            graphics.centeredText(this.font, avgText, left + width / 2, bottom - 60 - 9, -2039584);
            graphics.text(this.font, maxText, left + width - this.font.width(maxText) - 2, bottom - 60 - 9, -2039584);
        }
 
        this.extractAdditionalLinesAndLabels(graphics, left, width, bottom);
    }
 
    protected void extractSampleBars(GuiGraphicsExtractor graphics, int bottom, int currentX, int sampleIndex) {
        this.extractMainSampleBar(graphics, bottom, currentX, sampleIndex);
        this.extractAdditionalSampleBars(graphics, bottom, currentX, sampleIndex);
    }
 
    protected void extractMainSampleBar(GuiGraphicsExtractor graphics, int bottom, int currentX, int sampleIndex) {
        long value = this.sampleStorage.get(sampleIndex);
        int sampleHeight = this.getSampleHeight(value);
        int color = this.getSampleColor(value);
        graphics.fill(currentX, bottom - sampleHeight, currentX + 1, bottom, color);
    }
 
    protected void extractAdditionalSampleBars(GuiGraphicsExtractor graphics, int bottom, int currentX, int sampleIndex) {
    }
 
    protected long getValueForAggregation(int sampleIndex) {
        return this.sampleStorage.get(sampleIndex);
    }
 
    protected void extractAdditionalLinesAndLabels(GuiGraphicsExtractor graphics, int left, int width, int bottom) {
    }
 
    protected void extractStringWithShade(GuiGraphicsExtractor graphics, String str, int x, int y) {
        graphics.fill(x, y, x + this.font.width(str) + 1, y + 9, -1873784752);
        graphics.text(this.font, str, x + 1, y + 1, -2039584, false);
    }
 
    protected abstract String toDisplayString(double sample);
 
    protected abstract int getSampleHeight(double sample);
 
    protected abstract int getSampleColor(long sample);
 
    protected int getSampleColor(double sample, double min, int minColor, double mid, int midColor, double max, int maxColor) {
        sample = Mth.clamp(sample, min, max);
        return sample < mid
            ? ARGB.srgbLerp((float)((sample - min) / (mid - min)), minColor, midColor)
            : ARGB.srgbLerp((float)((sample - mid) / (max - mid)), midColor, maxColor);
    }
}

引用的其他类

  • Font

    • 引用位置: 参数/字段
  • GuiGraphicsExtractor

    • 引用位置: 参数
  • ARGB

    • 引用位置: 方法调用
    • 关联成员: ARGB.srgbLerp()
  • Mth

    • 引用位置: 方法调用
    • 关联成员: Mth.clamp()
  • SampleStorage

    • 引用位置: 参数/字段