From 1b646ee787159dfa0d169aae66dce1b4615eef6b Mon Sep 17 00:00:00 2001 From: mckuhei Date: Thu, 30 Mar 2023 14:29:15 +0800 Subject: [PATCH] Oops --- .../net/minecraft/client/Minecraft.java | 27 +++++++++++- .../net/minecraft/src/EntityRenderer.java | 2 +- .../net/minecraft/src/GuiIngame.java | 2 +- .../net/minecraft/src/MathHelper.java | 6 +++ src/minecraft/net/minecraft/src/Profiler.java | 43 ++++++++++++------- .../net/minecraft/src/RenderGlobal.java | 6 +-- src/minecraft/net/minecraft/src/World.java | 1 + 7 files changed, 66 insertions(+), 21 deletions(-) diff --git a/src/minecraft/net/minecraft/client/Minecraft.java b/src/minecraft/net/minecraft/client/Minecraft.java index 5dd04ed..134956b 100644 --- a/src/minecraft/net/minecraft/client/Minecraft.java +++ b/src/minecraft/net/minecraft/client/Minecraft.java @@ -9,6 +9,9 @@ import java.awt.Frame; import java.awt.Graphics; import java.io.File; import java.io.IOException; +import java.lang.management.GarbageCollectorMXBean; +import java.lang.management.ManagementFactory; + import org.mcmodule.math.BigInteger; import java.nio.ByteBuffer; import java.text.DecimalFormat; @@ -272,6 +275,7 @@ public abstract class Minecraft implements Runnable, IPlayerUsage /** holds the current fps */ int fpsCounter = 0; long prevFrameTime = -1L; + private long lastUpdateGCCollectedObjects, lastUpdateGCUsedTime; public Minecraft(Canvas par1Canvas, MinecraftApplet par2MinecraftApplet, int par3, int par4, boolean par5) { @@ -865,6 +869,8 @@ public abstract class Minecraft implements Runnable, IPlayerUsage { this.toggleFullscreen(); } + + if (this.gameSettings.showDebugInfo && this.gameSettings.field_74329_Q) { @@ -890,6 +896,18 @@ public abstract class Minecraft implements Runnable, IPlayerUsage this.guiAchievement.updateAchievementWindow(); this.mcProfiler.startSection("root"); + long gcUsedTime = 0; + for(GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { + long time = gc.getCollectionTime(); + if(time > 0) gcUsedTime += time; + } + + long time = gcUsedTime - lastUpdateGCUsedTime; + if(gcUsedTime > 0) { + this.mcProfiler.startSection("gc"); + this.mcProfiler.endSectionWithTime(time * 1000000); + } + lastUpdateGCUsedTime = gcUsedTime; Thread.yield(); if (Keyboard.isKeyDown(65)) @@ -929,9 +947,16 @@ public abstract class Minecraft implements Runnable, IPlayerUsage while (getSystemTime() >= this.debugUpdateTime + 1000L) { + long gcCollectedObjects = 0; + for(GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { + long count = gc.getCollectionCount(); + if(count > 0) gcCollectedObjects += count; + } + long collectedObjects = gcCollectedObjects - lastUpdateGCCollectedObjects; + lastUpdateGCCollectedObjects = gcCollectedObjects; field_71470_ab = this.fpsCounter; this.debug = field_71470_ab + " fps, " + WorldRenderer.chunksUpdated + " chunk updates"; - this.extraDebug = String.format("BC: %d, BR: %d", BigInteger.getAndClearCreateCounter(), BigInteger.getAndClearFreeCounter()); + this.extraDebug = String.format("BC: %d, OR: %d", BigInteger.getAndClearCreateCounter(), collectedObjects); WorldRenderer.chunksUpdated = 0; this.debugUpdateTime += 1000L; this.fpsCounter = 0; diff --git a/src/minecraft/net/minecraft/src/EntityRenderer.java b/src/minecraft/net/minecraft/src/EntityRenderer.java index aace12a..25295a1 100644 --- a/src/minecraft/net/minecraft/src/EntityRenderer.java +++ b/src/minecraft/net/minecraft/src/EntityRenderer.java @@ -937,7 +937,7 @@ public class EntityRenderer this.mc.mcProfiler.endStartSection("pick"); this.getMouseOver(par1); - EntityLiving var4 = this.mc.renderViewEntity; + EntityPlayer var4 = (EntityPlayer) this.mc.renderViewEntity; RenderGlobal var5 = this.mc.renderGlobal; EffectRenderer var6 = this.mc.effectRenderer; double var7 = var4.lastTickPosX + (var4.posX - var4.lastTickPosX) * (double)par1; diff --git a/src/minecraft/net/minecraft/src/GuiIngame.java b/src/minecraft/net/minecraft/src/GuiIngame.java index 4f15113..c547611 100644 --- a/src/minecraft/net/minecraft/src/GuiIngame.java +++ b/src/minecraft/net/minecraft/src/GuiIngame.java @@ -430,7 +430,7 @@ public class GuiIngame extends Gui } this.drawString(var8, String.format("ws: %.3f, fs: %.3f, g: %b", new Object[] {Float.valueOf(this.mc.thePlayer.capabilities.getWalkSpeed()), Float.valueOf(this.mc.thePlayer.capabilities.getFlySpeed()), Boolean.valueOf(this.mc.thePlayer.onGround)}), 2, 104, 14737632); - int maxBit = mc.thePlayer.posXBig.max(mc.thePlayer.posZBig).toBigInteger().bitLength(); + int maxBit = mc.thePlayer.posXBig.abs().max(mc.thePlayer.posZBig.abs()).toBigInteger().bitLength(); double doublePrecision = Math.pow(2, (maxBit - 53)), floatPrecision = Math.pow(2, (maxBit - 24)); diff --git a/src/minecraft/net/minecraft/src/MathHelper.java b/src/minecraft/net/minecraft/src/MathHelper.java index 2f21ebc..46b6542 100644 --- a/src/minecraft/net/minecraft/src/MathHelper.java +++ b/src/minecraft/net/minecraft/src/MathHelper.java @@ -1,6 +1,8 @@ package net.minecraft.src; import java.math.BigDecimal; +import java.math.RoundingMode; + import org.mcmodule.math.BigInteger; import java.util.Random; @@ -76,6 +78,10 @@ public class MathHelper return new BigInteger(String.format("%.0f", Math.floor(normalize(val)))); } + public static BigInteger floor_double_BigInteger(BigDecimal val) { + return new BigInteger(val.setScale(0, RoundingMode.FLOOR).toBigInteger().toByteArray()); + } + public static BigInteger toBigInteger(double val) { val = normalize(val); val = val < 0 ? Math.floor(val) + 1 : Math.floor(val); diff --git a/src/minecraft/net/minecraft/src/Profiler.java b/src/minecraft/net/minecraft/src/Profiler.java index d9eed40..ccf237e 100644 --- a/src/minecraft/net/minecraft/src/Profiler.java +++ b/src/minecraft/net/minecraft/src/Profiler.java @@ -66,25 +66,38 @@ public class Profiler this.sectionList.remove(this.sectionList.size() - 1); long var5 = var1 - var3; - if (this.profilingMap.containsKey(this.profilingSection)) - { - this.profilingMap.put(this.profilingSection, Long.valueOf(((Long)this.profilingMap.get(this.profilingSection)).longValue() + var5)); - } - else - { - this.profilingMap.put(this.profilingSection, Long.valueOf(var5)); - } + endSection(var5); + } + } + + public void endSectionWithTime(long time) { + if (this.profilingEnabled) + { + this.timestampList.remove(this.timestampList.size() - 1); + this.sectionList.remove(this.sectionList.size() - 1); + endSection(time); + } + } - if (var5 > 100000000L) - { - System.out.println("Something\'s taking too long! \'" + this.profilingSection + "\' took aprox " + (double)var5 / 1000000.0D + " ms"); - } + private void endSection(long var5) { + if (this.profilingMap.containsKey(this.profilingSection)) + { + this.profilingMap.put(this.profilingSection, Long.valueOf(((Long)this.profilingMap.get(this.profilingSection)).longValue() + var5)); + } + else + { + this.profilingMap.put(this.profilingSection, Long.valueOf(var5)); + } - this.profilingSection = !this.sectionList.isEmpty() ? (String)this.sectionList.get(this.sectionList.size() - 1) : ""; + if (var5 > 100000000L) + { + System.out.println("Something\'s taking too long! \'" + this.profilingSection + "\' took aprox " + (double)var5 / 1000000.0D + " ms"); } - } - /** + this.profilingSection = !this.sectionList.isEmpty() ? (String)this.sectionList.get(this.sectionList.size() - 1) : ""; + } + + /** * Get profiling data */ public List getProfilingData(String par1Str) diff --git a/src/minecraft/net/minecraft/src/RenderGlobal.java b/src/minecraft/net/minecraft/src/RenderGlobal.java index 8afbbaa..bb5326d 100644 --- a/src/minecraft/net/minecraft/src/RenderGlobal.java +++ b/src/minecraft/net/minecraft/src/RenderGlobal.java @@ -564,7 +564,7 @@ public class RenderGlobal implements IWorldAccess /** * Sorts all renderers based on the passed in entity. Args: entityLiving, renderPass, partialTickTime */ - public int sortAndRender(EntityLiving par1EntityLiving, int par2, double par3) + public int sortAndRender(EntityPlayer par1EntityLiving, int par2, double par3) { this.theWorld.theProfiler.startSection("sortchunks"); @@ -606,7 +606,7 @@ public class RenderGlobal implements IWorldAccess this.prevSortX = par1EntityLiving.posX; this.prevSortY = par1EntityLiving.posY; this.prevSortZ = par1EntityLiving.posZ; - this.markRenderersForNewPosition(MathHelper.floor_double_BigInteger(par1EntityLiving.posX), MathHelper.floor_double(par1EntityLiving.posY), MathHelper.floor_double_BigInteger(par1EntityLiving.posZ)); + this.markRenderersForNewPosition(MathHelper.floor_double_BigInteger(par1EntityLiving.posXBig), MathHelper.floor_double(par1EntityLiving.posY), MathHelper.floor_double_BigInteger(par1EntityLiving.posZBig)); Arrays.sort(this.sortedWorldRenderers, new EntitySorter(par1EntityLiving)); } @@ -817,7 +817,7 @@ public class RenderGlobal implements IWorldAccess var18.func_78421_b(); } - WorldRenderer var22; + WorldRenderer var22 = null; for (Iterator var21 = this.glRenderLists.iterator(); var21.hasNext(); this.allRenderLists[var17].func_78420_a(var22.getGLCallListForPass(par3))) { diff --git a/src/minecraft/net/minecraft/src/World.java b/src/minecraft/net/minecraft/src/World.java index e49dbb1..c34c30c 100644 --- a/src/minecraft/net/minecraft/src/World.java +++ b/src/minecraft/net/minecraft/src/World.java @@ -1344,6 +1344,7 @@ public abstract class World implements IBlockAccess public List getCollidingBoundingBoxes(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) { this.collidingBoundingBoxes.clear(); + if(Double.isInfinite(par2AxisAlignedBB.minX) || Double.isInfinite(par2AxisAlignedBB.maxX) || Double.isInfinite(par2AxisAlignedBB.minZ) || Double.isInfinite(par2AxisAlignedBB.maxZ)) return this.collidingBoundingBoxes; BigInteger var3 = MathHelper.floor_double_BigInteger(par2AxisAlignedBB.minX); BigInteger var4 = MathHelper.floor_double_BigInteger(par2AxisAlignedBB.maxX + 1.0D); int var5 = MathHelper.floor_double(par2AxisAlignedBB.minY);