VisGraph.java

net.minecraft.client.renderer.chunk.VisGraph

信息

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

    TODO

字段/常量

  • SIZE_IN_BITS

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

      TODO

  • LEN

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

      TODO

  • MASK

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

      TODO

  • SIZE

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

      TODO

  • X_SHIFT

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

      TODO

  • Z_SHIFT

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

      TODO

  • Y_SHIFT

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

      TODO

  • DX

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

      TODO

  • DZ

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

      TODO

  • DY

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

      TODO

  • INVALID_INDEX

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

      TODO

  • DIRECTIONS

    • 类型: Direction[]
    • 修饰符: private static final
    • 源码定位: L27
    • 说明:

      TODO

  • bitSet

    • 类型: BitSet
    • 修饰符: private final
    • 源码定位: L28
    • 说明:

      TODO

  • INDEX_OF_EDGES

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

      TODO

  • empty

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

      TODO

内部类/嵌套类型

构造器

方法

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

public void setOpaque(BlockPos pos) @ L46

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

参数:

  • pos: BlockPos

说明:

TODO

private static int getIndex(BlockPos pos) @ L51

  • 方法名:getIndex
  • 源码定位:L51
  • 返回类型:int
  • 修饰符:private static

参数:

  • pos: BlockPos

说明:

TODO

private static int getIndex(int x, int y, int z) @ L55

  • 方法名:getIndex
  • 源码定位:L55
  • 返回类型:int
  • 修饰符:private static

参数:

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

说明:

TODO

public VisibilitySet resolve() @ L59

  • 方法名:resolve
  • 源码定位:L59
  • 返回类型:VisibilitySet
  • 修饰符:public

参数:

说明:

TODO

private Set<Direction> floodFill(int startIndex) @ L76

  • 方法名:floodFill
  • 源码定位:L76
  • 返回类型:Set
  • 修饰符:private

参数:

  • startIndex: int

说明:

TODO

private void addEdges(int index, Set<Direction> edges) @ L98

  • 方法名:addEdges
  • 源码定位:L98
  • 返回类型:void
  • 修饰符:private

参数:

  • index: int
  • edges: Set

说明:

TODO

private int getNeighborIndexAtFace(int index, Direction direction) @ L121

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

参数:

  • index: int
  • direction: Direction

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class VisGraph {
    private static final int SIZE_IN_BITS = 4;
    private static final int LEN = 16;
    private static final int MASK = 15;
    private static final int SIZE = 4096;
    private static final int X_SHIFT = 0;
    private static final int Z_SHIFT = 4;
    private static final int Y_SHIFT = 8;
    private static final int DX = (int)Math.pow(16.0, 0.0);
    private static final int DZ = (int)Math.pow(16.0, 1.0);
    private static final int DY = (int)Math.pow(16.0, 2.0);
    private static final int INVALID_INDEX = -1;
    private static final Direction[] DIRECTIONS = Direction.values();
    private final BitSet bitSet = new BitSet(4096);
    private static final int[] INDEX_OF_EDGES = Util.make(new int[1352], map -> {
        int min = 0;
        int max = 15;
        int index = 0;
 
        for (int x = 0; x < 16; x++) {
            for (int y = 0; y < 16; y++) {
                for (int z = 0; z < 16; z++) {
                    if (x == 0 || x == 15 || y == 0 || y == 15 || z == 0 || z == 15) {
                        map[index++] = getIndex(x, y, z);
                    }
                }
            }
        }
    });
    private int empty = 4096;
 
    public void setOpaque(BlockPos pos) {
        this.bitSet.set(getIndex(pos), true);
        this.empty--;
    }
 
    private static int getIndex(BlockPos pos) {
        return getIndex(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15);
    }
 
    private static int getIndex(int x, int y, int z) {
        return x << 0 | y << 8 | z << 4;
    }
 
    public VisibilitySet resolve() {
        VisibilitySet visibilitySet = new VisibilitySet();
        if (4096 - this.empty < 256) {
            visibilitySet.setAll(true);
        } else if (this.empty == 0) {
            visibilitySet.setAll(false);
        } else {
            for (int i : INDEX_OF_EDGES) {
                if (!this.bitSet.get(i)) {
                    visibilitySet.add(this.floodFill(i));
                }
            }
        }
 
        return visibilitySet;
    }
 
    private Set<Direction> floodFill(int startIndex) {
        Set<Direction> edges = EnumSet.noneOf(Direction.class);
        IntPriorityQueue queue = new IntArrayFIFOQueue();
        queue.enqueue(startIndex);
        this.bitSet.set(startIndex, true);
 
        while (!queue.isEmpty()) {
            int index = queue.dequeueInt();
            this.addEdges(index, edges);
 
            for (Direction direction : DIRECTIONS) {
                int neighborIndex = this.getNeighborIndexAtFace(index, direction);
                if (neighborIndex >= 0 && !this.bitSet.get(neighborIndex)) {
                    this.bitSet.set(neighborIndex, true);
                    queue.enqueue(neighborIndex);
                }
            }
        }
 
        return edges;
    }
 
    private void addEdges(int index, Set<Direction> edges) {
        int x = index >> 0 & 15;
        if (x == 0) {
            edges.add(Direction.WEST);
        } else if (x == 15) {
            edges.add(Direction.EAST);
        }
 
        int y = index >> 8 & 15;
        if (y == 0) {
            edges.add(Direction.DOWN);
        } else if (y == 15) {
            edges.add(Direction.UP);
        }
 
        int z = index >> 4 & 15;
        if (z == 0) {
            edges.add(Direction.NORTH);
        } else if (z == 15) {
            edges.add(Direction.SOUTH);
        }
    }
 
    private int getNeighborIndexAtFace(int index, Direction direction) {
        switch (direction) {
            case DOWN:
                if ((index >> 8 & 15) == 0) {
                    return -1;
                }
 
                return index - DY;
            case UP:
                if ((index >> 8 & 15) == 15) {
                    return -1;
                }
 
                return index + DY;
            case NORTH:
                if ((index >> 4 & 15) == 0) {
                    return -1;
                }
 
                return index - DZ;
            case SOUTH:
                if ((index >> 4 & 15) == 15) {
                    return -1;
                }
 
                return index + DZ;
            case WEST:
                if ((index >> 0 & 15) == 0) {
                    return -1;
                }
 
                return index - DX;
            case EAST:
                if ((index >> 0 & 15) == 15) {
                    return -1;
                }
 
                return index + DX;
            default:
                return -1;
        }
    }
}

引用的其他类

  • VisibilitySet

    • 引用位置: 构造调用/返回值
    • 关联成员: VisibilitySet()
  • BlockPos

    • 引用位置: 参数
  • Direction

    • 引用位置: 参数/字段/方法调用/返回值
    • 关联成员: Direction.values()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.make()