massive optimizations to packet sending, close #2128
This commit is contained in:
parent
02bb70ec53
commit
885e7b0a1a
5 changed files with 25 additions and 38 deletions
|
@ -15,32 +15,35 @@ import org.apache.logging.log4j.Level;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
||||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||||
import cpw.mods.fml.common.network.FMLOutboundHandler.OutboundTarget;
|
import cpw.mods.fml.common.network.FMLOutboundHandler.OutboundTarget;
|
||||||
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
|
||||||
import buildcraft.api.core.BCLog;
|
import buildcraft.api.core.BCLog;
|
||||||
import buildcraft.core.network.BuildCraftPacket;
|
import buildcraft.core.network.BuildCraftPacket;
|
||||||
|
|
||||||
public class BuildCraftMod {
|
public class BuildCraftMod {
|
||||||
public EnumMap<Side, FMLEmbeddedChannel> channels;
|
public EnumMap<Side, FMLEmbeddedChannel> channels;
|
||||||
|
|
||||||
public void sendToPlayers(Packet packet, World world, int x, int y, int z, int maxDistance) {
|
public void sendToPlayers(BuildCraftPacket packet, World world, int x, int y, int z, int maxDistance) {
|
||||||
try {
|
try {
|
||||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||||
.set(FMLOutboundHandler.OutboundTarget.ALL);
|
.set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
|
||||||
|
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS)
|
||||||
|
.set(new NetworkRegistry.TargetPoint(world.provider.dimensionId, x, y, z, maxDistance));
|
||||||
channels.get(Side.SERVER).writeOutbound(packet);
|
channels.get(Side.SERVER).writeOutbound(packet);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
BCLog.logger.log(Level.WARN, "sentToPlayers crash", t);
|
BCLog.logger.log(Level.WARN, "sentToPlayers crash", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToPlayers(BuildCraftPacket packet, World world, int x, int y, int z, int maxDistance) {
|
public void sendToWorld(BuildCraftPacket packet, World world) {
|
||||||
try {
|
try {
|
||||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||||
.set(FMLOutboundHandler.OutboundTarget.ALL);
|
.set(FMLOutboundHandler.OutboundTarget.DIMENSION);
|
||||||
|
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS)
|
||||||
|
.set(world.provider.dimensionId);
|
||||||
channels.get(Side.SERVER).writeOutbound(packet);
|
channels.get(Side.SERVER).writeOutbound(packet);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
BCLog.logger.log(Level.WARN, "sentToPlayers crash", t);
|
BCLog.logger.log(Level.WARN, "sentToPlayers crash", t);
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class PacketRPCTile extends PacketRPC {
|
||||||
|
|
||||||
dimId = data.readShort();
|
dimId = data.readShort();
|
||||||
x = data.readInt();
|
x = data.readInt();
|
||||||
y = data.readInt();
|
y = data.readShort();
|
||||||
z = data.readInt();
|
z = data.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ public class PacketRPCTile extends PacketRPC {
|
||||||
// small. Maybe worth using a varint instead
|
// small. Maybe worth using a varint instead
|
||||||
data.writeShort(tile.getWorldObj().provider.dimensionId);
|
data.writeShort(tile.getWorldObj().provider.dimensionId);
|
||||||
data.writeInt(tile.xCoord);
|
data.writeInt(tile.xCoord);
|
||||||
data.writeInt(tile.yCoord);
|
data.writeShort(tile.yCoord);
|
||||||
data.writeInt(tile.zCoord);
|
data.writeInt(tile.zCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class PacketUpdate extends BuildCraftPacket {
|
||||||
public void writeData(ByteBuf data) {
|
public void writeData(ByteBuf data) {
|
||||||
data.writeByte(packetId);
|
data.writeByte(packetId);
|
||||||
data.writeInt(posX);
|
data.writeInt(posX);
|
||||||
data.writeInt(posY);
|
data.writeShort(posY);
|
||||||
data.writeInt(posZ);
|
data.writeInt(posZ);
|
||||||
|
|
||||||
if (payload != null) {
|
if (payload != null) {
|
||||||
|
@ -57,7 +57,7 @@ public class PacketUpdate extends BuildCraftPacket {
|
||||||
public void readData(ByteBuf data) {
|
public void readData(ByteBuf data) {
|
||||||
packetId = data.readByte();
|
packetId = data.readByte();
|
||||||
posX = data.readInt();
|
posX = data.readInt();
|
||||||
posY = data.readInt();
|
posY = data.readShort();
|
||||||
posZ = data.readInt();
|
posZ = data.readInt();
|
||||||
|
|
||||||
if (data.isReadable()) {
|
if (data.isReadable()) {
|
||||||
|
|
|
@ -37,10 +37,6 @@ public class TilePacketWrapper {
|
||||||
return new PacketPayload(new PacketPayload.StreamWriter() {
|
return new PacketPayload(new PacketPayload.StreamWriter() {
|
||||||
@Override
|
@Override
|
||||||
public void writeData(ByteBuf data) {
|
public void writeData(ByteBuf data) {
|
||||||
data.writeInt(tile.xCoord);
|
|
||||||
data.writeInt(tile.yCoord);
|
|
||||||
data.writeInt(tile.zCoord);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SerializationContext context = new SerializationContext();
|
SerializationContext context = new SerializationContext();
|
||||||
rootMappings[0].write(data, tile, context);
|
rootMappings[0].write(data, tile, context);
|
||||||
|
@ -65,10 +61,6 @@ public class TilePacketWrapper {
|
||||||
return new PacketPayload(new PacketPayload.StreamWriter() {
|
return new PacketPayload(new PacketPayload.StreamWriter() {
|
||||||
@Override
|
@Override
|
||||||
public void writeData(ByteBuf data) {
|
public void writeData(ByteBuf data) {
|
||||||
data.writeInt(x);
|
|
||||||
data.writeInt(y);
|
|
||||||
data.writeInt(z);
|
|
||||||
|
|
||||||
for (int i = 0; i < rootMappings.length; ++i) {
|
for (int i = 0; i < rootMappings.length; ++i) {
|
||||||
try {
|
try {
|
||||||
SerializationContext context = new SerializationContext();
|
SerializationContext context = new SerializationContext();
|
||||||
|
@ -88,10 +80,6 @@ public class TilePacketWrapper {
|
||||||
try {
|
try {
|
||||||
ByteBuf data = packet.stream;
|
ByteBuf data = packet.stream;
|
||||||
|
|
||||||
data.readInt();
|
|
||||||
data.readInt();
|
|
||||||
data.readInt();
|
|
||||||
|
|
||||||
SerializationContext context = new SerializationContext();
|
SerializationContext context = new SerializationContext();
|
||||||
rootMappings[0].read(data, tile, context);
|
rootMappings[0].read(data, tile, context);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -107,10 +95,6 @@ public class TilePacketWrapper {
|
||||||
try {
|
try {
|
||||||
ByteBuf data = packet.stream;
|
ByteBuf data = packet.stream;
|
||||||
|
|
||||||
data.readInt();
|
|
||||||
data.readInt();
|
|
||||||
data.readInt();
|
|
||||||
|
|
||||||
for (int i = 0; i < rootMappings.length; ++i) {
|
for (int i = 0; i < rootMappings.length; ++i) {
|
||||||
SerializationContext context = new SerializationContext();
|
SerializationContext context = new SerializationContext();
|
||||||
rootMappings[i].read(data, obj[i], context);
|
rootMappings[i].read(data, obj[i], context);
|
||||||
|
|
|
@ -45,8 +45,8 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable
|
||||||
private int powerIndex = 0;
|
private int powerIndex = 0;
|
||||||
|
|
||||||
@NetworkData
|
@NetworkData
|
||||||
private double powerAverage = 0;
|
private short powerAverage = 0;
|
||||||
private final double[] power = new double[POWER_AVERAGING];
|
private final short[] power = new short[POWER_AVERAGING];
|
||||||
|
|
||||||
public TileLaser() {
|
public TileLaser() {
|
||||||
super();
|
super();
|
||||||
|
@ -125,7 +125,7 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable
|
||||||
return 40;
|
return 40;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPowerSent(double power) {
|
protected void onPowerSent(int power) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean canFindTable() {
|
protected boolean canFindTable() {
|
||||||
|
@ -279,10 +279,10 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable
|
||||||
return isValidTable();
|
return isValidTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushPower(double received) {
|
private void pushPower(int received) {
|
||||||
powerAverage -= power[powerIndex];
|
powerAverage -= power[powerIndex];
|
||||||
powerAverage += received;
|
powerAverage += received;
|
||||||
power[powerIndex] = received;
|
power[powerIndex] = (short) received;
|
||||||
powerIndex++;
|
powerIndex++;
|
||||||
|
|
||||||
if (powerIndex == power.length) {
|
if (powerIndex == power.length) {
|
||||||
|
|
Loading…
Reference in a new issue