ViewArea.java

net.minecraft.client.renderer.ViewArea

信息

  • 全限定名:net.minecraft.client.renderer.ViewArea
  • 类型:public class
  • 包:net.minecraft.client.renderer
  • 源码路径:src/main/java/net/minecraft/client/renderer/ViewArea.java
  • 起始行号:L14
  • 职责:

    TODO

字段/常量

  • levelRenderer

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

      TODO

  • level

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

      TODO

  • sectionGridSizeY

    • 类型: int
    • 修饰符: protected
    • 源码定位: L17
    • 说明:

      TODO

  • sectionGridSizeX

    • 类型: int
    • 修饰符: protected
    • 源码定位: L18
    • 说明:

      TODO

  • sectionGridSizeZ

    • 类型: int
    • 修饰符: protected
    • 源码定位: L19
    • 说明:

      TODO

  • viewDistance

    • 类型: int
    • 修饰符: private
    • 源码定位: L20
    • 说明:

      TODO

  • cameraSectionPos

    • 类型: SectionPos
    • 修饰符: private
    • 源码定位: L21
    • 说明:

      TODO

  • sections

    • 类型: SectionRenderDispatcher.RenderSection[]
    • 修饰符: public
    • 源码定位: L22
    • 说明:

      TODO

内部类/嵌套类型

构造器

public ViewArea(SectionRenderDispatcher sectionRenderDispatcher, Level level, int renderDistance, LevelRenderer levelRenderer) @ L24

  • 构造器名:ViewArea
  • 源码定位:L24
  • 修饰符:public

参数:

  • sectionRenderDispatcher: SectionRenderDispatcher
  • level: Level
  • renderDistance: int
  • levelRenderer: LevelRenderer

说明:

TODO

方法

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

protected void createSections(SectionRenderDispatcher sectionRenderDispatcher) @ L32

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

参数:

  • sectionRenderDispatcher: SectionRenderDispatcher

说明:

TODO

public void releaseAllBuffers() @ L50

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

参数:

说明:

TODO

private int getSectionIndex(int x, int y, int z) @ L56

  • 方法名:getSectionIndex
  • 源码定位:L56
  • 返回类型:int
  • 修饰符:private

参数:

  • x: int
  • y: int
  • z: int

说明:

TODO

protected void setViewDistance(int renderDistance) @ L60

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

参数:

  • renderDistance: int

说明:

TODO

public int getViewDistance() @ L68

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

参数:

说明:

TODO

public LevelHeightAccessor getLevelHeightAccessor() @ L72

  • 方法名:getLevelHeightAccessor
  • 源码定位:L72
  • 返回类型:LevelHeightAccessor
  • 修饰符:public

参数:

说明:

TODO

public void repositionCamera(SectionPos cameraSectionPos) @ L76

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

参数:

  • cameraSectionPos: SectionPos

说明:

TODO

public SectionPos getCameraSectionPos() @ L100

  • 方法名:getCameraSectionPos
  • 源码定位:L100
  • 返回类型:SectionPos
  • 修饰符:public

参数:

说明:

TODO

public void setDirty(int sectionX, int sectionY, int sectionZ, boolean playerChanged) @ L104

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

参数:

  • sectionX: int
  • sectionY: int
  • sectionZ: int
  • playerChanged: boolean

说明:

TODO

protected SectionRenderDispatcher.RenderSection getRenderSectionAt(BlockPos pos) @ L111

  • 方法名:getRenderSectionAt
  • 源码定位:L111
  • 返回类型:SectionRenderDispatcher.RenderSection
  • 修饰符:protected

参数:

  • pos: BlockPos

说明:

TODO

protected SectionRenderDispatcher.RenderSection getRenderSection(long sectionNode) @ L115

  • 方法名:getRenderSection
  • 源码定位:L115
  • 返回类型:SectionRenderDispatcher.RenderSection
  • 修饰符:protected

参数:

  • sectionNode: long

说明:

TODO

private SectionRenderDispatcher.RenderSection getRenderSection(int sectionX, int sectionY, int sectionZ) @ L122

  • 方法名:getRenderSection
  • 源码定位:L122
  • 返回类型:SectionRenderDispatcher.RenderSection
  • 修饰符:private

参数:

  • sectionX: int
  • sectionY: int
  • sectionZ: int

说明:

TODO

private boolean containsSection(int sectionX, int sectionY, int sectionZ) @ L133

  • 方法名:containsSection
  • 源码定位:L133
  • 返回类型:boolean
  • 修饰符:private

参数:

  • sectionX: int
  • sectionY: int
  • sectionZ: int

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ViewArea {
    protected final LevelRenderer levelRenderer;
    protected final Level level;
    protected int sectionGridSizeY;
    protected int sectionGridSizeX;
    protected int sectionGridSizeZ;
    private int viewDistance;
    private SectionPos cameraSectionPos;
    public SectionRenderDispatcher.RenderSection[] sections;
 
    public ViewArea(SectionRenderDispatcher sectionRenderDispatcher, Level level, int renderDistance, LevelRenderer levelRenderer) {
        this.levelRenderer = levelRenderer;
        this.level = level;
        this.setViewDistance(renderDistance);
        this.createSections(sectionRenderDispatcher);
        this.cameraSectionPos = SectionPos.of(this.viewDistance + 1, 0, this.viewDistance + 1);
    }
 
    protected void createSections(SectionRenderDispatcher sectionRenderDispatcher) {
        if (!Minecraft.getInstance().isSameThread()) {
            throw new IllegalStateException("createSections called from wrong thread: " + Thread.currentThread().getName());
        } else {
            int totalSections = this.sectionGridSizeX * this.sectionGridSizeY * this.sectionGridSizeZ;
            this.sections = new SectionRenderDispatcher.RenderSection[totalSections];
 
            for (int x = 0; x < this.sectionGridSizeX; x++) {
                for (int y = 0; y < this.sectionGridSizeY; y++) {
                    for (int z = 0; z < this.sectionGridSizeZ; z++) {
                        int index = this.getSectionIndex(x, y, z);
                        this.sections[index] = sectionRenderDispatcher.new RenderSection(index, SectionPos.asLong(x, y + this.level.getMinSectionY(), z));
                    }
                }
            }
        }
    }
 
    public void releaseAllBuffers() {
        for (SectionRenderDispatcher.RenderSection section : this.sections) {
            section.reset();
        }
    }
 
    private int getSectionIndex(int x, int y, int z) {
        return (z * this.sectionGridSizeY + y) * this.sectionGridSizeX + x;
    }
 
    protected void setViewDistance(int renderDistance) {
        int dist = renderDistance * 2 + 1;
        this.sectionGridSizeX = dist;
        this.sectionGridSizeY = this.level.getSectionsCount();
        this.sectionGridSizeZ = dist;
        this.viewDistance = renderDistance;
    }
 
    public int getViewDistance() {
        return this.viewDistance;
    }
 
    public LevelHeightAccessor getLevelHeightAccessor() {
        return this.level;
    }
 
    public void repositionCamera(SectionPos cameraSectionPos) {
        for (int gridX = 0; gridX < this.sectionGridSizeX; gridX++) {
            int lowestX = cameraSectionPos.x() - this.viewDistance;
            int newSectionX = lowestX + Math.floorMod(gridX - lowestX, this.sectionGridSizeX);
 
            for (int gridZ = 0; gridZ < this.sectionGridSizeZ; gridZ++) {
                int lowestZ = cameraSectionPos.z() - this.viewDistance;
                int newSectionZ = lowestZ + Math.floorMod(gridZ - lowestZ, this.sectionGridSizeZ);
 
                for (int gridY = 0; gridY < this.sectionGridSizeY; gridY++) {
                    int newSectionY = this.level.getMinSectionY() + gridY;
                    SectionRenderDispatcher.RenderSection section = this.sections[this.getSectionIndex(gridX, gridY, gridZ)];
                    long sectionNode = section.getSectionNode();
                    if (sectionNode != SectionPos.asLong(newSectionX, newSectionY, newSectionZ)) {
                        section.setSectionNode(SectionPos.asLong(newSectionX, newSectionY, newSectionZ));
                    }
                }
            }
        }
 
        this.cameraSectionPos = cameraSectionPos;
        this.levelRenderer.getSectionOcclusionGraph().invalidate();
    }
 
    public SectionPos getCameraSectionPos() {
        return this.cameraSectionPos;
    }
 
    public void setDirty(int sectionX, int sectionY, int sectionZ, boolean playerChanged) {
        SectionRenderDispatcher.RenderSection section = this.getRenderSection(sectionX, sectionY, sectionZ);
        if (section != null) {
            section.setDirty(playerChanged);
        }
    }
 
    protected SectionRenderDispatcher.@Nullable RenderSection getRenderSectionAt(BlockPos pos) {
        return this.getRenderSection(SectionPos.asLong(pos));
    }
 
    protected SectionRenderDispatcher.@Nullable RenderSection getRenderSection(long sectionNode) {
        int sectionX = SectionPos.x(sectionNode);
        int sectionY = SectionPos.y(sectionNode);
        int sectionZ = SectionPos.z(sectionNode);
        return this.getRenderSection(sectionX, sectionY, sectionZ);
    }
 
    private SectionRenderDispatcher.@Nullable RenderSection getRenderSection(int sectionX, int sectionY, int sectionZ) {
        if (!this.containsSection(sectionX, sectionY, sectionZ)) {
            return null;
        } else {
            int y = sectionY - this.level.getMinSectionY();
            int x = Math.floorMod(sectionX, this.sectionGridSizeX);
            int z = Math.floorMod(sectionZ, this.sectionGridSizeZ);
            return this.sections[this.getSectionIndex(x, y, z)];
        }
    }
 
    private boolean containsSection(int sectionX, int sectionY, int sectionZ) {
        if (sectionY >= this.level.getMinSectionY() && sectionY <= this.level.getMaxSectionY()) {
            return sectionX < this.cameraSectionPos.x() - this.viewDistance || sectionX > this.cameraSectionPos.x() + this.viewDistance
                ? false
                : sectionZ >= this.cameraSectionPos.z() - this.viewDistance && sectionZ <= this.cameraSectionPos.z() + this.viewDistance;
        } else {
            return false;
        }
    }
}

引用的其他类

  • Minecraft

    • 引用位置: 方法调用
    • 关联成员: Minecraft.getInstance()
  • LevelRenderer

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

    • 引用位置: 参数/字段/构造调用/返回值
    • 关联成员: RenderSection()
  • BlockPos

    • 引用位置: 参数
  • SectionPos

    • 引用位置: 参数/字段/方法调用/返回值
    • 关联成员: SectionPos.asLong(), SectionPos.of(), SectionPos.x(), SectionPos.y(), SectionPos.z()
  • Level

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

    • 引用位置: 返回值