Skip to content

Commit

Permalink
chore: use soft references for cached chunk packets
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBauHD committed Dec 15, 2023
1 parent 40bab93 commit 0363af3
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.netty.buffer.ByteBufAllocator;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashSet;
Expand All @@ -38,7 +39,7 @@ public final class SculkChunk implements Chunk {
private final Set<AbstractEntity> entities = new HashSet<>();
private final Int2ObjectMap<Block.Entity<?>> blockEntities = new Int2ObjectOpenHashMap<>();

private ChunkDataAndUpdateLight packet;
private SoftReference<ChunkDataAndUpdateLight> packet;

public SculkChunk(final SculkWorld world, final int chunkX, final int chunkZ) {
this(world, chunkX, chunkZ, newSections(world.dimension()),
Expand Down Expand Up @@ -137,18 +138,18 @@ public void send(SculkPlayer player) {
emptyBlockMask.set(index);
}
}
this.packet = new ChunkDataAndUpdateLight(
this.packet = new SoftReference<>(new ChunkDataAndUpdateLight(
this.x,
this.z,
this.heightmaps,
buf.readAll(),
new LightData(skyMask, blockMask, emptySkyMask, emptyBlockMask,
skyLight.toArray(new byte[][]{}), blockLight.toArray(new byte[][]{})),
this.blockEntities
);
));
buf.close();
}
player.send(this.packet);
player.send(this.packet.get());
}

public Section section(final int y) {
Expand Down

0 comments on commit 0363af3

Please sign in to comment.