Search in sources :

Example 1 with ChunkOcclusionGraphExt

use of grondag.canvas.chunk.occlusion.ChunkOcclusionGraphExt in project canvas by vram-guild.

the class MixinChunkOcclusionGraphBuilder method buildFast.

@Inject(method = "build", at = @At("HEAD"), cancellable = true, require = 1)
public void buildFast(CallbackInfoReturnable<ChunkOcclusionData> ci) {
    if (Configurator.fastChunkOcclusion) {
        // PERF: any way to avoid allocation?
        final ChunkOcclusionData result = new ChunkOcclusionData();
        if (4096 - openCount < 256) {
            // set all visible
            result.fill(true);
            ((ChunkOcclusionGraphExt) result).canvas_visibilityData(DirectionSet.ALL);
        } else if (openCount == 0) {
            result.fill(false);
            ((ChunkOcclusionGraphExt) result).canvas_visibilityData(DirectionSet.NONE);
        } else {
            final BitSet bitSet = closed;
            final ChunkOcclusionMap facingMap = ChunkOcclusionMap.claim();
            for (final int i : EDGE_POINTS) {
                if (!bitSet.get(i)) {
                    final Pair<Set<Direction>, IntArrayList> floodResult = getOpenFacesFast(i);
                    final Set<Direction> fillSet = floodResult.getLeft();
                    // set multiple visible
                    result.addOpenEdgeFaces(fillSet);
                    final byte setIndex = (byte) DirectionSet.sharedIndex(fillSet);
                    final IntArrayList list = floodResult.getRight();
                    final int limit = list.size();
                    for (int j = 0; j < limit; j++) {
                        facingMap.setIndex(list.getInt(j), setIndex);
                    }
                }
            }
            ((ChunkOcclusionGraphExt) result).canvas_visibilityData(facingMap);
        }
        ci.setReturnValue(result);
    }
}
Also used : ChunkOcclusionData(net.minecraft.client.render.chunk.ChunkOcclusionData) ChunkOcclusionGraphExt(grondag.canvas.chunk.occlusion.ChunkOcclusionGraphExt) Set(java.util.Set) BitSet(java.util.BitSet) DirectionSet(grondag.canvas.chunk.occlusion.DirectionSet) ChunkOcclusionMap(grondag.canvas.chunk.occlusion.ChunkOcclusionMap) BitSet(java.util.BitSet) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) Direction(net.minecraft.util.math.Direction) Pair(org.apache.commons.lang3.tuple.Pair) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ChunkOcclusionGraphExt (grondag.canvas.chunk.occlusion.ChunkOcclusionGraphExt)1 ChunkOcclusionMap (grondag.canvas.chunk.occlusion.ChunkOcclusionMap)1 DirectionSet (grondag.canvas.chunk.occlusion.DirectionSet)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 BitSet (java.util.BitSet)1 Set (java.util.Set)1 ChunkOcclusionData (net.minecraft.client.render.chunk.ChunkOcclusionData)1 Direction (net.minecraft.util.math.Direction)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1