mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
More RAM optimizations with buffer releasing. Also fix a bug in RBMK processing and a few merge-related errors.
This commit is contained in:
parent
7a16a8ba9f
commit
85743e85f4
@ -37,6 +37,7 @@ import com.hbm.world.biome.BiomeGenCraterBase;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.PooledByteBufAllocator;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
@ -80,7 +81,7 @@ public class EntityEffectHandler {
|
||||
if(entity instanceof EntityPlayerMP) {
|
||||
HbmLivingProps props = HbmLivingProps.getData(entity);
|
||||
HbmPlayerProps pprps = HbmPlayerProps.getData((EntityPlayerMP) entity);
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
|
||||
|
||||
if(pprps.shield < pprps.getEffectiveMaxShield() && entity.ticksExisted > pprps.lastDamage + 60) {
|
||||
int tsd = entity.ticksExisted - (pprps.lastDamage + 60);
|
||||
@ -93,6 +94,7 @@ public class EntityEffectHandler {
|
||||
props.serialize(buf);
|
||||
pprps.serialize(buf);
|
||||
PacketDispatcher.wrapper.sendTo(new ExtPropPacket(buf), (EntityPlayerMP) entity);
|
||||
buf.release();
|
||||
}
|
||||
|
||||
if(!entity.worldObj.isRemote) {
|
||||
|
||||
@ -17,7 +17,7 @@ public class NeutronHandler {
|
||||
private static int ticks = 0;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerTick(TickEvent.ServerTickEvent event) {
|
||||
public void onServerTick(TickEvent.ServerTickEvent event) {
|
||||
if(event.phase != TickEvent.Phase.START)
|
||||
return;
|
||||
|
||||
|
||||
@ -48,18 +48,20 @@ public class PacketThreading {
|
||||
*/
|
||||
public static void waitUntilThreadFinished() {
|
||||
try {
|
||||
for(Future<?> future : futureList) {
|
||||
future.get(50, TimeUnit.MILLISECONDS); // I HATE EVERYTHING
|
||||
if (!(processedCnt >= totalCnt)) {
|
||||
for (Future<?> future : futureList) {
|
||||
future.get(50, TimeUnit.MILLISECONDS); // I HATE EVERYTHING
|
||||
}
|
||||
}
|
||||
futureList.clear();
|
||||
} catch (ExecutionException ignored) {
|
||||
// impossible
|
||||
} catch (TimeoutException e) {
|
||||
MainRegistry.logger.warn("A packet has taken >50ms to process, discarding {}/{} packets to prevent pausing of main thread.", totalCnt-processedCnt, totalCnt);
|
||||
MainRegistry.logger.warn("A packet has taken >50ms to process, discarding {}/{} packets to prevent pausing of main thread ({} total futures).", totalCnt-processedCnt, totalCnt, futureList.size());
|
||||
threadPool.getQueue().clear();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt(); // maybe not the best thing but it's gotta be here
|
||||
} finally {
|
||||
futureList.clear();
|
||||
processedCnt = 0;
|
||||
totalCnt = 0;
|
||||
}
|
||||
|
||||
@ -17,10 +17,7 @@
|
||||
import com.hbm.entity.effect.*;
|
||||
import com.hbm.entity.grenade.*;
|
||||
import com.hbm.entity.item.*;
|
||||
import com.hbm.entity.logic.EntityBomber;
|
||||
import com.hbm.entity.logic.EntityDeathBlast;
|
||||
import com.hbm.entity.logic.EntityEMP;
|
||||
import com.hbm.entity.logic.EntityWaypoint;
|
||||
import com.hbm.entity.logic.*;
|
||||
import com.hbm.entity.missile.*;
|
||||
import com.hbm.entity.missile.EntityMissileTier0.*;
|
||||
import com.hbm.entity.missile.EntityMissileTier1.*;
|
||||
|
||||
@ -17,6 +17,7 @@ import com.hbm.handler.imc.IMCBlastFurnace;
|
||||
import com.hbm.handler.imc.IMCCentrifuge;
|
||||
import com.hbm.handler.imc.IMCCrystallizer;
|
||||
import com.hbm.handler.imc.IMCHandler;
|
||||
import com.hbm.handler.neutron.NeutronHandler;
|
||||
import com.hbm.handler.pollution.PollutionHandler;
|
||||
import com.hbm.handler.radiation.ChunkRadiationManager;
|
||||
import com.hbm.hazard.HazardRegistry;
|
||||
@ -909,6 +910,10 @@ public class MainRegistry {
|
||||
|
||||
PacketDispatcher.registerPackets();
|
||||
|
||||
NeutronHandler neutronHandler = new NeutronHandler();
|
||||
MinecraftForge.EVENT_BUS.register(neutronHandler);
|
||||
FMLCommonHandler.instance().bus().register(neutronHandler);
|
||||
|
||||
ChunkRadiationManager radiationSystem = new ChunkRadiationManager();
|
||||
MinecraftForge.EVENT_BUS.register(radiationSystem);
|
||||
FMLCommonHandler.instance().bus().register(radiationSystem);
|
||||
|
||||
@ -55,6 +55,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.WorldTickEvent;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.PooledByteBufAllocator;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.command.CommandGameRule;
|
||||
@ -1223,9 +1224,10 @@ public class ModEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
|
||||
HbmPlayerProps.getData(event.original).serialize(buf);
|
||||
HbmPlayerProps.getData(event.entityPlayer).deserialize(buf);
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@ -66,7 +66,6 @@ import com.hbm.wiaj.cannery.Jars;
|
||||
import com.hbm.util.ArmorRegistry;
|
||||
import com.hbm.util.ArmorUtil;
|
||||
import com.hbm.util.DamageResistanceHandler;
|
||||
import com.hbm.util.ArmorRegistry.HazardClass;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
@ -112,10 +111,7 @@ import net.minecraftforge.client.GuiIngameForge;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import net.minecraftforge.client.IRenderHandler;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.client.event.FOVUpdateEvent;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.*;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
||||
import net.minecraftforge.client.event.sound.PlaySoundEvent17;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
@ -25,7 +25,11 @@ public abstract class PrecompiledPacket implements IMessage {
|
||||
* Forcefully creates the precompiled buffer, use `getPreBuf()` whenever possible.
|
||||
*/
|
||||
public void makePreBuf() {
|
||||
if(preCompiledBuf != null)
|
||||
preCompiledBuf.release();
|
||||
|
||||
preCompiledBuf = Unpooled.buffer();
|
||||
|
||||
this.toBytes(preCompiledBuf); // Create buffer and read data to it.
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,6 +71,8 @@ public class AuxParticlePacketNT implements IMessage {
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
m.buffer.release();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@ -61,6 +61,8 @@ public class BufPacket extends PrecompiledPacket {
|
||||
MainRegistry.logger.warn("A ByteBuf packet failed to be read and has thrown an error. This normally means that there was a buffer underflow and more data was read than was actually in the packet.");
|
||||
MainRegistry.logger.warn("Tile: {}", te.getBlockType().getUnlocalizedName());
|
||||
MainRegistry.logger.warn(e.getMessage());
|
||||
} finally {
|
||||
m.buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -52,15 +52,13 @@ public class ExtPropPacket implements IMessage {
|
||||
if(Minecraft.getMinecraft().theWorld == null)
|
||||
return null;
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
|
||||
m.toBytes(buf);
|
||||
|
||||
HbmLivingProps props = HbmLivingProps.getData(Minecraft.getMinecraft().thePlayer);
|
||||
HbmPlayerProps pprps = HbmPlayerProps.getData(Minecraft.getMinecraft().thePlayer);
|
||||
|
||||
props.deserialize(buf);
|
||||
pprps.deserialize(buf);
|
||||
props.deserialize(m.buffer);
|
||||
pprps.deserialize(m.buffer);
|
||||
|
||||
m.buffer.release();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public class PermaSyncPacket implements IMessage {
|
||||
|
||||
|
||||
EntityPlayerMP player; //server only, for writing
|
||||
ByteBuf out; //client only, for reading
|
||||
|
||||
@ -34,18 +34,20 @@ public class PermaSyncPacket implements IMessage {
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<PermaSyncPacket, IMessage> {
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IMessage onMessage(PermaSyncPacket m, MessageContext ctx) {
|
||||
|
||||
|
||||
try {
|
||||
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
if(player != null) PermaSyncHandler.readPacket(m.out, player.worldObj, player);
|
||||
|
||||
} catch(Exception x) { }
|
||||
|
||||
|
||||
} catch(Exception x) { } finally {
|
||||
m.out.release();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
public class SatPanelPacket implements IMessage {
|
||||
|
||||
|
||||
PacketBuffer buffer;
|
||||
int type;
|
||||
|
||||
@ -31,10 +31,10 @@ public class SatPanelPacket implements IMessage {
|
||||
this.buffer = new PacketBuffer(Unpooled.buffer());
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
sat.writeToNBT(nbt);
|
||||
|
||||
|
||||
try {
|
||||
buffer.writeNBTTagCompoundToBuffer(nbt);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -42,9 +42,9 @@ public class SatPanelPacket implements IMessage {
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
|
||||
|
||||
type = buf.readInt();
|
||||
|
||||
|
||||
if (buffer == null) {
|
||||
buffer = new PacketBuffer(Unpooled.buffer());
|
||||
}
|
||||
@ -53,9 +53,9 @@ public class SatPanelPacket implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
|
||||
|
||||
buf.writeInt(type);
|
||||
|
||||
|
||||
if (buffer == null) {
|
||||
buffer = new PacketBuffer(Unpooled.buffer());
|
||||
}
|
||||
@ -67,18 +67,20 @@ public class SatPanelPacket implements IMessage {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IMessage onMessage(SatPanelPacket m, MessageContext ctx) {
|
||||
|
||||
|
||||
Minecraft.getMinecraft();
|
||||
|
||||
try {
|
||||
|
||||
|
||||
NBTTagCompound nbt = m.buffer.readNBTTagCompoundFromBuffer();
|
||||
ItemSatInterface.currentSat = Satellite.create(m.type);
|
||||
|
||||
|
||||
if(nbt != null)
|
||||
ItemSatInterface.currentSat.readFromNBT(nbt);
|
||||
|
||||
|
||||
} catch (Exception x) {
|
||||
} finally {
|
||||
m.buffer.release();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class NBTControlPacket implements IMessage {
|
||||
|
||||
|
||||
PacketBuffer buffer;
|
||||
int x;
|
||||
int y;
|
||||
@ -24,12 +24,12 @@ public class NBTControlPacket implements IMessage {
|
||||
public NBTControlPacket() { }
|
||||
|
||||
public NBTControlPacket(NBTTagCompound nbt, int x, int y, int z) {
|
||||
|
||||
|
||||
this.buffer = new PacketBuffer(Unpooled.buffer());
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
|
||||
try {
|
||||
buffer.writeNBTTagCompoundToBuffer(nbt);
|
||||
} catch (IOException e) {
|
||||
@ -39,60 +39,62 @@ public class NBTControlPacket implements IMessage {
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
|
||||
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
|
||||
|
||||
if(buffer == null) buffer = new PacketBuffer(Unpooled.buffer());
|
||||
|
||||
|
||||
buffer.writeBytes(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
|
||||
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
|
||||
|
||||
if (buffer == null) buffer = new PacketBuffer(Unpooled.buffer());
|
||||
|
||||
|
||||
buf.writeBytes(buffer);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<NBTControlPacket, IMessage> {
|
||||
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(NBTControlPacket m, MessageContext ctx) {
|
||||
|
||||
EntityPlayer p = ctx.getServerHandler().playerEntity;
|
||||
|
||||
|
||||
if(p.worldObj == null)
|
||||
return null;
|
||||
|
||||
|
||||
TileEntity te = p.worldObj.getTileEntity(m.x, m.y, m.z);
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
NBTTagCompound nbt = m.buffer.readNBTTagCompoundFromBuffer();
|
||||
|
||||
|
||||
if(nbt != null) {
|
||||
if(te instanceof IControlReceiver) {
|
||||
|
||||
|
||||
IControlReceiver tile = (IControlReceiver)te;
|
||||
|
||||
|
||||
if(tile.hasPermission(p)) {
|
||||
tile.receiveControl(p, nbt);
|
||||
tile.receiveControl(nbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
m.buffer.release();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,18 +15,18 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
public class NBTItemControlPacket implements IMessage {
|
||||
|
||||
|
||||
PacketBuffer buffer;
|
||||
|
||||
public NBTItemControlPacket() { }
|
||||
|
||||
public NBTItemControlPacket(NBTTagCompound nbt) {
|
||||
|
||||
|
||||
this.buffer = new PacketBuffer(Unpooled.buffer());
|
||||
|
||||
|
||||
try {
|
||||
buffer.writeNBTTagCompoundToBuffer(nbt);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -34,7 +34,7 @@ public class NBTItemControlPacket implements IMessage {
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
|
||||
|
||||
if (buffer == null) {
|
||||
buffer = new PacketBuffer(Unpooled.buffer());
|
||||
}
|
||||
@ -43,7 +43,7 @@ public class NBTItemControlPacket implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
|
||||
|
||||
if (buffer == null) {
|
||||
buffer = new PacketBuffer(Unpooled.buffer());
|
||||
}
|
||||
@ -51,28 +51,30 @@ public class NBTItemControlPacket implements IMessage {
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<NBTItemControlPacket, IMessage> {
|
||||
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(NBTItemControlPacket m, MessageContext ctx) {
|
||||
|
||||
EntityPlayer p = ctx.getServerHandler().playerEntity;
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
NBTTagCompound nbt = m.buffer.readNBTTagCompoundFromBuffer();
|
||||
|
||||
|
||||
if(nbt != null) {
|
||||
ItemStack held = p.getHeldItem();
|
||||
|
||||
|
||||
if(held != null && held.getItem() instanceof IItemControlReceiver) {
|
||||
((IItemControlReceiver) held.getItem()).receiveControl(held, nbt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
m.buffer.release();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,6 +65,8 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
if(this.buf != null)
|
||||
this.buf.release();
|
||||
this.buf = Unpooled.buffer();
|
||||
|
||||
buf.writeBoolean(this.hasExploded);
|
||||
|
||||
@ -57,6 +57,8 @@ public class TileEntityHeatBoilerIndustrial extends TileEntityLoadedBase impleme
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
if(this.buf != null)
|
||||
this.buf.release();
|
||||
this.buf = Unpooled.buffer();
|
||||
|
||||
this.setupTanks();
|
||||
|
||||
@ -52,6 +52,8 @@ public class TileEntityMachineHephaestus extends TileEntityLoadedBase implements
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
if(this.buf != null)
|
||||
this.buf.release();
|
||||
this.buf = Unpooled.buffer();
|
||||
|
||||
setupTanks();
|
||||
|
||||
@ -77,6 +77,8 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
if(this.buf != null)
|
||||
this.buf.release();
|
||||
this.buf = Unpooled.buffer();
|
||||
|
||||
this.powerBuffer = 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user