mirror of
https://github.com/Minestom/Minestom.git
synced 2024-08-20 19:33:05 +02:00
Small optimizations to netty.
This commit is contained in:
parent
4e11b16ee1
commit
926c02b7f5
|
@ -606,7 +606,7 @@ public final class MinecraftServer {
|
|||
*
|
||||
* @return should process netty errors
|
||||
*/
|
||||
public static boolean processingNettyErrors() {
|
||||
public static boolean shouldProcessNettyErrors() {
|
||||
return processNettyErrors;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.minestom.server.network.netty;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.epoll.Epoll;
|
||||
import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||
|
@ -100,6 +101,7 @@ public final class NettyServer {
|
|||
ChannelConfig config = ch.config();
|
||||
config.setOption(ChannelOption.TCP_NODELAY, true);
|
||||
config.setOption(ChannelOption.SO_SNDBUF, 1_000_000);
|
||||
config.setAllocator(ByteBufAllocator.DEFAULT);
|
||||
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
|
||||
|
|
|
@ -65,8 +65,10 @@ public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
|
|||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
LOGGER.info(cause.getMessage());
|
||||
cause.printStackTrace();
|
||||
if (MinecraftServer.shouldProcessNettyErrors()) {
|
||||
LOGGER.info(cause.getMessage());
|
||||
cause.printStackTrace();
|
||||
}
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,22 @@ public class GroupedPacketHandler extends MessageToByteEncoder<FramedPacket> {
|
|||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, FramedPacket msg, ByteBuf out) {
|
||||
final ByteBuf packet = msg.body;
|
||||
out.writeBytes(packet.duplicate());
|
||||
|
||||
out.setBytes(0, packet, 0, packet.writerIndex());
|
||||
out.writerIndex(packet.writerIndex());
|
||||
|
||||
if (msg.releaseBuf) {
|
||||
packet.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, FramedPacket msg, boolean preferDirect) {
|
||||
if (preferDirect) {
|
||||
return ctx.alloc().ioBuffer(msg.body.writerIndex());
|
||||
} else {
|
||||
return ctx.alloc().heapBuffer(msg.body.writerIndex());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||
}
|
||||
|
||||
public void write(Object message) {
|
||||
if (MinecraftServer.processingNettyErrors())
|
||||
if (MinecraftServer.shouldProcessNettyErrors())
|
||||
channel.write(message).addListener(future -> {
|
||||
if (!future.isSuccess()) {
|
||||
future.cause().printStackTrace();
|
||||
|
@ -154,7 +154,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||
}
|
||||
|
||||
public void writeAndFlush(Object message) {
|
||||
if (MinecraftServer.processingNettyErrors())
|
||||
if (MinecraftServer.shouldProcessNettyErrors())
|
||||
channel.writeAndFlush(message).addListener(future -> {
|
||||
if (!future.isSuccess()) {
|
||||
future.cause().printStackTrace();
|
||||
|
|
|
@ -49,11 +49,11 @@ public class PlayerInit {
|
|||
instanceContainer.setChunkGenerator(noiseTestGenerator);
|
||||
|
||||
// Load some chunks beforehand
|
||||
final int loopStart = -32;
|
||||
final int loopEnd = 32;
|
||||
final int loopStart = -16;
|
||||
final int loopEnd = 16;
|
||||
for (int x = loopStart; x < loopEnd; x++)
|
||||
for (int z = loopStart; z < loopEnd; z++) {
|
||||
instanceContainer.loadChunk(x, z);
|
||||
//instanceContainer.loadChunk(x, z);
|
||||
}
|
||||
|
||||
inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
||||
|
@ -172,9 +172,9 @@ public class PlayerInit {
|
|||
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
||||
|
||||
event.setSpawningInstance(instanceContainer);
|
||||
int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 + 500;
|
||||
int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 + 500;
|
||||
player.setRespawnPoint(new Position(0, 70f, 0));
|
||||
int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000;
|
||||
int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000;
|
||||
player.setRespawnPoint(new Position(x, 70f, z));
|
||||
|
||||
/*player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||
if (slot == -999)
|
||||
|
|
Loading…
Reference in New Issue
Block a user