use of it.unimi.dsi.fastutil.objects.ObjectArrayFIFOQueue in project sodium-fabric by CaffeineMC.
the class ChunkGraph method init.
private boolean init(BlockPos blockPos, Camera camera, Vec3d cameraPos, Frustum frustum, int frame, boolean spectator) {
MinecraftClient client = MinecraftClient.getInstance();
ObjectArrayFIFOQueue<ChunkGraphNode<T>> queue = this.iterationQueue;
boolean cull = client.chunkCullingEnabled;
ChunkGraphNode<T> node = this.getOrCreateNode(blockPos);
if (node != null) {
node.reset();
// Player is within bounds and inside a node
Set<Direction> openFaces = this.getOpenChunkFaces(blockPos);
if (openFaces.size() == 1) {
Vector3f vector3f = camera.getHorizontalPlane();
Direction direction = Direction.getFacing(vector3f.getX(), vector3f.getY(), vector3f.getZ()).getOpposite();
openFaces.remove(direction);
}
if (openFaces.isEmpty() && !spectator) {
this.visibleNodes.add(node);
} else {
if (spectator && this.world.getBlockState(blockPos).isFullOpaque(this.world, blockPos)) {
cull = false;
}
node.setRebuildFrame(frame);
queue.enqueue(node);
}
} else {
// Player is out-of-bounds
int y = blockPos.getY() > 0 ? 248 : 8;
int x = MathHelper.floor(cameraPos.x / 16.0D) * 16;
int z = MathHelper.floor(cameraPos.z / 16.0D) * 16;
List<ChunkGraphNode<T>> list = Lists.newArrayList();
for (int x2 = -this.renderDistance; x2 <= this.renderDistance; ++x2) {
for (int z2 = -this.renderDistance; z2 <= this.renderDistance; ++z2) {
ChunkGraphNode<T> chunk = this.getOrCreateNode(new BlockPos(x + (x2 << 4) + 8, y, z + (z2 << 4) + 8));
if (chunk == null) {
continue;
}
if (frustum.isVisible(chunk.getBoundingBox())) {
chunk.setRebuildFrame(frame);
chunk.reset();
list.add(chunk);
}
}
}
list.sort(Comparator.comparingDouble(o -> blockPos.getSquaredDistance(o.chunk.getOrigin().add(8, 8, 8))));
for (ChunkGraphNode<T> n : list) {
queue.enqueue(n);
}
}
return cull;
}
Aggregations