mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 02:57:37 +01:00
Block/chunk batching should be much faster
This commit is contained in:
parent
7daac5e610
commit
90925b4967
@ -10,6 +10,7 @@ import net.minestom.server.instance.block.Block;
|
|||||||
import net.minestom.server.instance.block.BlockManager;
|
import net.minestom.server.instance.block.BlockManager;
|
||||||
import net.minestom.server.instance.block.CustomBlock;
|
import net.minestom.server.instance.block.CustomBlock;
|
||||||
import net.minestom.server.instance.block.UpdateConsumer;
|
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.network.packet.server.play.ChunkDataPacket;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
import net.minestom.server.utils.PacketUtils;
|
import net.minestom.server.utils.PacketUtils;
|
||||||
@ -307,6 +308,14 @@ public class Chunk implements Viewable {
|
|||||||
setFullDataPacket(buffer);
|
setFullDataPacket(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the pakcet in the writer thread pools
|
||||||
|
public void refreshDataPacket(Runnable runnable) {
|
||||||
|
PacketWriterUtils.writeCallbackPacket(getFreshFullDataPacket(), buf -> {
|
||||||
|
setFullDataPacket(buf);
|
||||||
|
runnable.run();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Chunk[" + chunkX + ":" + chunkZ + "]";
|
return "Chunk[" + chunkX + ":" + chunkZ + "]";
|
||||||
|
@ -66,13 +66,17 @@ public class BlockBatch implements InstanceBatch {
|
|||||||
for (BlockData data : dataList) {
|
for (BlockData data : dataList) {
|
||||||
data.apply(chunk);
|
data.apply(chunk);
|
||||||
}
|
}
|
||||||
chunk.refreshDataPacket();
|
|
||||||
instance.sendChunkUpdate(chunk);
|
chunk.refreshDataPacket(() -> {
|
||||||
|
instance.sendChunkUpdate(chunk);
|
||||||
|
});
|
||||||
|
|
||||||
if (isLast) {
|
if (isLast) {
|
||||||
// data.clear();
|
// data.clear();
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.run();
|
callback.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,10 @@ public class ChunkBatch implements InstanceBatch {
|
|||||||
data.apply(chunk);
|
data.apply(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk.refreshDataPacket();
|
chunk.refreshDataPacket(() -> {
|
||||||
instance.sendChunkUpdate(chunk);
|
instance.sendChunkUpdate(chunk);
|
||||||
|
});
|
||||||
|
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.accept(chunk);
|
callback.accept(chunk);
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,10 @@ public class PlayerPositionAndLookPacket implements ServerPacket {
|
|||||||
writer.writeDouble(position.getX());
|
writer.writeDouble(position.getX());
|
||||||
writer.writeDouble(position.getY());
|
writer.writeDouble(position.getY());
|
||||||
writer.writeDouble(position.getZ());
|
writer.writeDouble(position.getZ());
|
||||||
|
|
||||||
writer.writeFloat(position.getYaw());
|
writer.writeFloat(position.getYaw());
|
||||||
writer.writeFloat(position.getPitch());
|
writer.writeFloat(position.getPitch());
|
||||||
|
|
||||||
writer.writeByte(flags);
|
writer.writeByte(flags);
|
||||||
writer.writeVarInt(teleportId);
|
writer.writeVarInt(teleportId);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user