CompileTaskDynamicQueue.java

net.minecraft.client.renderer.chunk.CompileTaskDynamicQueue

信息

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

    TODO

字段/常量

  • MAX_RECOMPILE_QUOTA

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

      TODO

  • recompileQuota

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

      TODO

  • tasks

    • 类型: List<SectionRenderDispatcher.RenderSection.CompileTask>
    • 修饰符: private final
    • 源码定位: L15
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public synchronized void add(SectionRenderDispatcher.RenderSection.CompileTask task) @ L17

  • 方法名:add
  • 源码定位:L17
  • 返回类型:void
  • 修饰符:public synchronized

参数:

  • task: SectionRenderDispatcher.RenderSection.CompileTask

说明:

TODO

public synchronized SectionRenderDispatcher.RenderSection.CompileTask poll(Vec3 cameraPos) @ L21

  • 方法名:poll
  • 源码定位:L21
  • 返回类型:SectionRenderDispatcher.RenderSection.CompileTask
  • 修饰符:public synchronized

参数:

  • cameraPos: Vec3

说明:

TODO

public int size() @ L58

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

参数:

说明:

TODO

private SectionRenderDispatcher.RenderSection.CompileTask removeTaskByIndex(int taskIndex) @ L62

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

参数:

  • taskIndex: int

说明:

TODO

public synchronized void clear() @ L66

  • 方法名:clear
  • 源码定位:L66
  • 返回类型:void
  • 修饰符:public synchronized

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class CompileTaskDynamicQueue {
    private static final int MAX_RECOMPILE_QUOTA = 2;
    private int recompileQuota = 2;
    private final List<SectionRenderDispatcher.RenderSection.CompileTask> tasks = new ObjectArrayList<>();
 
    public synchronized void add(SectionRenderDispatcher.RenderSection.CompileTask task) {
        this.tasks.add(task);
    }
 
    public synchronized SectionRenderDispatcher.RenderSection.@Nullable CompileTask poll(Vec3 cameraPos) {
        int bestInitialCompileTaskIndex = -1;
        int bestRecompileTaskIndex = -1;
        double bestInitialCompileDistance = Double.MAX_VALUE;
        double bestRecompileDistance = Double.MAX_VALUE;
        ListIterator<SectionRenderDispatcher.RenderSection.CompileTask> iterator = this.tasks.listIterator();
 
        while (iterator.hasNext()) {
            int taskIndex = iterator.nextIndex();
            SectionRenderDispatcher.RenderSection.CompileTask task = iterator.next();
            if (task.isCancelled.get()) {
                iterator.remove();
            } else {
                double distance = task.getRenderOrigin().distToCenterSqr(cameraPos);
                if (!task.isRecompile() && distance < bestInitialCompileDistance) {
                    bestInitialCompileDistance = distance;
                    bestInitialCompileTaskIndex = taskIndex;
                }
 
                if (task.isRecompile() && distance < bestRecompileDistance) {
                    bestRecompileDistance = distance;
                    bestRecompileTaskIndex = taskIndex;
                }
            }
        }
 
        boolean hasRecompileTask = bestRecompileTaskIndex >= 0;
        boolean hasInitialCompileTask = bestInitialCompileTaskIndex >= 0;
        if (!hasRecompileTask || hasInitialCompileTask && (this.recompileQuota <= 0 || !(bestRecompileDistance < bestInitialCompileDistance))) {
            this.recompileQuota = 2;
            return this.removeTaskByIndex(bestInitialCompileTaskIndex);
        } else {
            this.recompileQuota--;
            return this.removeTaskByIndex(bestRecompileTaskIndex);
        }
    }
 
    public int size() {
        return this.tasks.size();
    }
 
    private SectionRenderDispatcher.RenderSection.@Nullable CompileTask removeTaskByIndex(int taskIndex) {
        return taskIndex >= 0 ? this.tasks.remove(taskIndex) : null;
    }
 
    public synchronized void clear() {
        for (SectionRenderDispatcher.RenderSection.CompileTask task : this.tasks) {
            task.cancel();
        }
 
        this.tasks.clear();
    }
}

引用的其他类