Block/chunk batching should be much faster

This commit is contained in:
Felix Cravic 2020-04-24 11:33:29 +02:00
parent 7daac5e610
commit 90925b4967
4 changed files with 21 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockManager;
import net.minestom.server.instance.block.CustomBlock;
import net.minestom.server.instance.block.UpdateConsumer;
import net.minestom.server.network.PacketWriterUtils;
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.PacketUtils;
@ -307,6 +308,14 @@ public class Chunk implements Viewable {
setFullDataPacket(buffer);
}
// Write the pakcet in the writer thread pools
public void refreshDataPacket(Runnable runnable) {
PacketWriterUtils.writeCallbackPacket(getFreshFullDataPacket(), buf -> {
setFullDataPacket(buf);
runnable.run();
});
}
@Override
public String toString() {
return "Chunk[" + chunkX + ":" + chunkZ + "]";

View File

@ -66,13 +66,17 @@ public class BlockBatch implements InstanceBatch {
for (BlockData data : dataList) {
data.apply(chunk);
}
chunk.refreshDataPacket();
instance.sendChunkUpdate(chunk);
chunk.refreshDataPacket(() -> {
instance.sendChunkUpdate(chunk);
});
if (isLast) {
// data.clear();
if (callback != null)
callback.run();
}
}
});
}

View File

@ -67,8 +67,10 @@ public class ChunkBatch implements InstanceBatch {
data.apply(chunk);
}
chunk.refreshDataPacket();
instance.sendChunkUpdate(chunk);
chunk.refreshDataPacket(() -> {
instance.sendChunkUpdate(chunk);
});
if (callback != null)
callback.accept(chunk);
}

View File

@ -17,8 +17,10 @@ public class PlayerPositionAndLookPacket implements ServerPacket {
writer.writeDouble(position.getX());
writer.writeDouble(position.getY());
writer.writeDouble(position.getZ());
writer.writeFloat(position.getYaw());
writer.writeFloat(position.getPitch());
writer.writeByte(flags);
writer.writeVarInt(teleportId);
}