Remove threadlocal buffer cache in ChunkDataPacket

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-02 18:44:50 +02:00
parent 399eb860a7
commit d4e51f562c
2 changed files with 8 additions and 3 deletions

View File

@ -33,7 +33,6 @@ public class ChunkDataPacket implements ServerPacket {
public Map<Integer, Block> entries = new HashMap<>();
private static final byte CHUNK_SECTION_COUNT = 16;
private static final PacketUtils.LocalCache BLOCK_CACHE = PacketUtils.LocalCache.get("chunk-block-cache", 262_144);
/**
* Heightmaps NBT, as read from raw packet data.
@ -49,7 +48,7 @@ public class ChunkDataPacket implements ServerPacket {
writer.writeInt(chunkX);
writer.writeInt(chunkZ);
ByteBuffer blocks = BLOCK_CACHE.get();
ByteBuffer blocks = PacketUtils.localBuffer();
Int2LongRBTreeMap maskMap = new Int2LongRBTreeMap();

View File

@ -38,6 +38,12 @@ public final class PacketUtils {
private PacketUtils() {
}
@ApiStatus.Internal
@ApiStatus.Experimental
public static ByteBuffer localBuffer() {
return COMPRESSION_CACHE.get();
}
/**
* Sends a packet to an audience. This method performs the following steps in the
* following order:
@ -200,7 +206,7 @@ public final class PacketUtils {
@ApiStatus.Internal
public static FramedPacket allocateTrimmedPacket(@NotNull ServerPacket packet) {
final var temp = PacketUtils.createFramedPacket(packet);
final var buffer= ByteBuffer.allocateDirect(temp.position()).put(temp.flip()).asReadOnlyBuffer();
final var buffer = ByteBuffer.allocateDirect(temp.position()).put(temp.flip()).asReadOnlyBuffer();
return new FramedPacket(packet.getId(), buffer, packet);
}