More RAM optimizations with buffer releasing. Also fix a bug in RBMK processing and a few merge-related errors.

This commit is contained in:
BallOfEnergy 2024-12-18 08:32:30 -06:00
parent 7a16a8ba9f
commit 85743e85f4
19 changed files with 97 additions and 71 deletions

View File

@ -37,6 +37,7 @@ import com.hbm.world.biome.BiomeGenCraterBase;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -80,7 +81,7 @@ public class EntityEffectHandler {
if(entity instanceof EntityPlayerMP) { if(entity instanceof EntityPlayerMP) {
HbmLivingProps props = HbmLivingProps.getData(entity); HbmLivingProps props = HbmLivingProps.getData(entity);
HbmPlayerProps pprps = HbmPlayerProps.getData((EntityPlayerMP) 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) { if(pprps.shield < pprps.getEffectiveMaxShield() && entity.ticksExisted > pprps.lastDamage + 60) {
int tsd = entity.ticksExisted - (pprps.lastDamage + 60); int tsd = entity.ticksExisted - (pprps.lastDamage + 60);
@ -93,6 +94,7 @@ public class EntityEffectHandler {
props.serialize(buf); props.serialize(buf);
pprps.serialize(buf); pprps.serialize(buf);
PacketDispatcher.wrapper.sendTo(new ExtPropPacket(buf), (EntityPlayerMP) entity); PacketDispatcher.wrapper.sendTo(new ExtPropPacket(buf), (EntityPlayerMP) entity);
buf.release();
} }
if(!entity.worldObj.isRemote) { if(!entity.worldObj.isRemote) {

View File

@ -17,7 +17,7 @@ public class NeutronHandler {
private static int ticks = 0; private static int ticks = 0;
@SubscribeEvent @SubscribeEvent
public static void onServerTick(TickEvent.ServerTickEvent event) { public void onServerTick(TickEvent.ServerTickEvent event) {
if(event.phase != TickEvent.Phase.START) if(event.phase != TickEvent.Phase.START)
return; return;

View File

@ -48,18 +48,20 @@ public class PacketThreading {
*/ */
public static void waitUntilThreadFinished() { public static void waitUntilThreadFinished() {
try { try {
for(Future<?> future : futureList) { if (!(processedCnt >= totalCnt)) {
future.get(50, TimeUnit.MILLISECONDS); // I HATE EVERYTHING for (Future<?> future : futureList) {
future.get(50, TimeUnit.MILLISECONDS); // I HATE EVERYTHING
}
} }
futureList.clear();
} catch (ExecutionException ignored) { } catch (ExecutionException ignored) {
// impossible // impossible
} catch (TimeoutException e) { } 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(); threadPool.getQueue().clear();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); // maybe not the best thing but it's gotta be here Thread.currentThread().interrupt(); // maybe not the best thing but it's gotta be here
} finally { } finally {
futureList.clear();
processedCnt = 0; processedCnt = 0;
totalCnt = 0; totalCnt = 0;
} }

View File

@ -17,10 +17,7 @@
import com.hbm.entity.effect.*; import com.hbm.entity.effect.*;
import com.hbm.entity.grenade.*; import com.hbm.entity.grenade.*;
import com.hbm.entity.item.*; import com.hbm.entity.item.*;
import com.hbm.entity.logic.EntityBomber; import com.hbm.entity.logic.*;
import com.hbm.entity.logic.EntityDeathBlast;
import com.hbm.entity.logic.EntityEMP;
import com.hbm.entity.logic.EntityWaypoint;
import com.hbm.entity.missile.*; import com.hbm.entity.missile.*;
import com.hbm.entity.missile.EntityMissileTier0.*; import com.hbm.entity.missile.EntityMissileTier0.*;
import com.hbm.entity.missile.EntityMissileTier1.*; import com.hbm.entity.missile.EntityMissileTier1.*;

View File

@ -17,6 +17,7 @@ import com.hbm.handler.imc.IMCBlastFurnace;
import com.hbm.handler.imc.IMCCentrifuge; import com.hbm.handler.imc.IMCCentrifuge;
import com.hbm.handler.imc.IMCCrystallizer; import com.hbm.handler.imc.IMCCrystallizer;
import com.hbm.handler.imc.IMCHandler; import com.hbm.handler.imc.IMCHandler;
import com.hbm.handler.neutron.NeutronHandler;
import com.hbm.handler.pollution.PollutionHandler; import com.hbm.handler.pollution.PollutionHandler;
import com.hbm.handler.radiation.ChunkRadiationManager; import com.hbm.handler.radiation.ChunkRadiationManager;
import com.hbm.hazard.HazardRegistry; import com.hbm.hazard.HazardRegistry;
@ -909,6 +910,10 @@ public class MainRegistry {
PacketDispatcher.registerPackets(); PacketDispatcher.registerPackets();
NeutronHandler neutronHandler = new NeutronHandler();
MinecraftForge.EVENT_BUS.register(neutronHandler);
FMLCommonHandler.instance().bus().register(neutronHandler);
ChunkRadiationManager radiationSystem = new ChunkRadiationManager(); ChunkRadiationManager radiationSystem = new ChunkRadiationManager();
MinecraftForge.EVENT_BUS.register(radiationSystem); MinecraftForge.EVENT_BUS.register(radiationSystem);
FMLCommonHandler.instance().bus().register(radiationSystem); FMLCommonHandler.instance().bus().register(radiationSystem);

View File

@ -55,6 +55,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.gameevent.TickEvent.WorldTickEvent; import cpw.mods.fml.common.gameevent.TickEvent.WorldTickEvent;
import cpw.mods.fml.relauncher.ReflectionHelper; import cpw.mods.fml.relauncher.ReflectionHelper;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.command.CommandGameRule; import net.minecraft.command.CommandGameRule;
@ -1223,9 +1224,10 @@ public class ModEventHandler {
@SubscribeEvent @SubscribeEvent
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) { 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.original).serialize(buf);
HbmPlayerProps.getData(event.entityPlayer).deserialize(buf); HbmPlayerProps.getData(event.entityPlayer).deserialize(buf);
buf.release();
} }
@SubscribeEvent @SubscribeEvent

View File

@ -66,7 +66,6 @@ import com.hbm.wiaj.cannery.Jars;
import com.hbm.util.ArmorRegistry; import com.hbm.util.ArmorRegistry;
import com.hbm.util.ArmorUtil; import com.hbm.util.ArmorUtil;
import com.hbm.util.DamageResistanceHandler; import com.hbm.util.DamageResistanceHandler;
import com.hbm.util.ArmorRegistry.HazardClass;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
@ -112,10 +111,7 @@ import net.minecraftforge.client.GuiIngameForge;
import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.IRenderHandler; import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.event.FOVUpdateEvent; import net.minecraftforge.client.event.*;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.sound.PlaySoundEvent17; import net.minecraftforge.client.event.sound.PlaySoundEvent17;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeHooks;

View File

@ -25,7 +25,11 @@ public abstract class PrecompiledPacket implements IMessage {
* Forcefully creates the precompiled buffer, use `getPreBuf()` whenever possible. * Forcefully creates the precompiled buffer, use `getPreBuf()` whenever possible.
*/ */
public void makePreBuf() { public void makePreBuf() {
if(preCompiledBuf != null)
preCompiledBuf.release();
preCompiledBuf = Unpooled.buffer(); preCompiledBuf = Unpooled.buffer();
this.toBytes(preCompiledBuf); // Create buffer and read data to it. this.toBytes(preCompiledBuf); // Create buffer and read data to it.
} }
} }

View File

@ -71,6 +71,8 @@ public class AuxParticlePacketNT implements IMessage {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
m.buffer.release();
} }
return null; return null;

View File

@ -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("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("Tile: {}", te.getBlockType().getUnlocalizedName());
MainRegistry.logger.warn(e.getMessage()); MainRegistry.logger.warn(e.getMessage());
} finally {
m.buf.release();
} }
} }

View File

@ -52,15 +52,13 @@ public class ExtPropPacket implements IMessage {
if(Minecraft.getMinecraft().theWorld == null) if(Minecraft.getMinecraft().theWorld == null)
return null; return null;
ByteBuf buf = Unpooled.buffer();
m.toBytes(buf);
HbmLivingProps props = HbmLivingProps.getData(Minecraft.getMinecraft().thePlayer); HbmLivingProps props = HbmLivingProps.getData(Minecraft.getMinecraft().thePlayer);
HbmPlayerProps pprps = HbmPlayerProps.getData(Minecraft.getMinecraft().thePlayer); HbmPlayerProps pprps = HbmPlayerProps.getData(Minecraft.getMinecraft().thePlayer);
props.deserialize(buf); props.deserialize(m.buffer);
pprps.deserialize(buf); pprps.deserialize(m.buffer);
m.buffer.release();
return null; return null;
} }

View File

@ -44,7 +44,9 @@ public class PermaSyncPacket implements IMessage {
EntityPlayer player = Minecraft.getMinecraft().thePlayer; EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if(player != null) PermaSyncHandler.readPacket(m.out, player.worldObj, player); if(player != null) PermaSyncHandler.readPacket(m.out, player.worldObj, player);
} catch(Exception x) { } } catch(Exception x) { } finally {
m.out.release();
}
return null; return null;
} }

View File

@ -79,6 +79,8 @@ public class SatPanelPacket implements IMessage {
ItemSatInterface.currentSat.readFromNBT(nbt); ItemSatInterface.currentSat.readFromNBT(nbt);
} catch (Exception x) { } catch (Exception x) {
} finally {
m.buffer.release();
} }
return null; return null;
} }

View File

@ -91,6 +91,8 @@ public class NBTControlPacket implements IMessage {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
m.buffer.release();
} }
return null; return null;

View File

@ -71,6 +71,8 @@ public class NBTItemControlPacket implements IMessage {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
m.buffer.release();
} }
return null; return null;

View File

@ -65,6 +65,8 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(this.buf != null)
this.buf.release();
this.buf = Unpooled.buffer(); this.buf = Unpooled.buffer();
buf.writeBoolean(this.hasExploded); buf.writeBoolean(this.hasExploded);

View File

@ -57,6 +57,8 @@ public class TileEntityHeatBoilerIndustrial extends TileEntityLoadedBase impleme
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(this.buf != null)
this.buf.release();
this.buf = Unpooled.buffer(); this.buf = Unpooled.buffer();
this.setupTanks(); this.setupTanks();

View File

@ -52,6 +52,8 @@ public class TileEntityMachineHephaestus extends TileEntityLoadedBase implements
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(this.buf != null)
this.buf.release();
this.buf = Unpooled.buffer(); this.buf = Unpooled.buffer();
setupTanks(); setupTanks();

View File

@ -77,6 +77,8 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(this.buf != null)
this.buf.release();
this.buf = Unpooled.buffer(); this.buf = Unpooled.buffer();
this.powerBuffer = 0; this.powerBuffer = 0;