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