Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,21 @@

public final class AllocationRateHUD {

private final boolean isDebug;
private long lastUpdateTime = System.nanoTime();
private long lastFreeMemory = Runtime.getRuntime().freeMemory();
private String cachedText = "";

public AllocationRateHUD(boolean isDebug) {
this.isDebug = isDebug;
}

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onRenderGameOverlayTextEvent(RenderGameOverlayEvent.Text event) {
if (isDebug && Minecraft.getMinecraft().gameSettings.showDebugInfo) {
this.updateText();
final int index = MathHelper.clamp_int(2, 0, event.right.size() - 1);
event.right.add(index, cachedText);
} else if (!isDebug && !Minecraft.getMinecraft().gameSettings.showDebugInfo) {
this.updateText();
if (!Minecraft.getMinecraft().gameSettings.showDebugInfo) {
final String text = this.updateText();
final FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
final int strWidth = fr.getStringWidth(cachedText);
fr.drawStringWithShadow(cachedText, event.resolution.getScaledWidth() - strWidth - 2, 2, 0xFFFFFFFF);
final int strWidth = fr.getStringWidth(text);
fr.drawStringWithShadow(text, event.resolution.getScaledWidth() - strWidth - 2, 2, 0xFFFFFFFF);
}
}

private void updateText() {
public String updateText() {
final long currentTime = System.nanoTime();
if (currentTime - lastUpdateTime >= 1_000_000_000L) {
final long currentFreeMemory = Runtime.getRuntime().freeMemory();
Expand All @@ -44,5 +35,6 @@ private void updateText() {
lastFreeMemory = currentFreeMemory;
lastUpdateTime = currentTime;
}
return cachedText;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.mitchej123.hodgepodge.client;

import net.minecraft.client.Minecraft;
import net.minecraft.world.gen.layer.IntCache;
import net.minecraftforge.client.event.RenderGameOverlayEvent;

import org.lwjgl.opengl.GL11;

import com.mitchej123.hodgepodge.config.DebugConfig;
import com.mitchej123.hodgepodge.config.TweaksConfig;

import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class DebugScreenHandler {

public static final DebugScreenHandler INSTANCE = new DebugScreenHandler();

private final AllocationRateHUD allocRate = new AllocationRateHUD();
private final boolean is64bit;
private final String javaVersion;
private final String javaVendor;
Expand All @@ -33,23 +37,33 @@ private DebugScreenHandler() {
this.osVersion = System.getProperty("os.version");
}

@SubscribeEvent
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onRenderGameOverlayTextEvent(RenderGameOverlayEvent.Text event) {
if (Minecraft.getMinecraft().gameSettings.showDebugInfo) {
int offset = event.right.isEmpty() ? 0 : 2;
event.right.add(offset, null); // Empty Line
event.right.add(
1 + offset,
"Java: " + this.javaVersion + (this.is64bit ? " 64bit (" : " 32bit (") + this.javaVendor + ")");
event.right.add(2 + offset, "GPU: " + this.gpuName);
event.right.add(3 + offset, "OpenGL: " + this.glVersion);
event.right.add(4 + offset, "CPU Cores: " + Runtime.getRuntime().availableProcessors());
event.right.add(5 + offset, "OS: " + this.osName + " (" + this.osVersion + ", " + this.osArch + ")");

if (DebugConfig.renderDebug) {
event.right.add(6 + offset, null); // Empty Line
int offset = 0;
for (int i = 0; i < event.right.size(); i++) {
final String s = event.right.get(i);
if (s != null && s.startsWith("Allocated memory: ")) {
offset = i + 1;
break;
}
}
event.right.add(offset, this.allocRate.updateText());
event.right.add(1 + offset, IntCache.getCacheSizes());
if (TweaksConfig.addSystemInfo) {
event.right.add(2 + offset, null); // Empty Line
event.right.add(
3 + offset,
"Java: " + this.javaVersion + (this.is64bit ? " 64bit (" : " 32bit (") + this.javaVendor + ")");
event.right.add(4 + offset, "GPU: " + this.gpuName);
event.right.add(5 + offset, "OpenGL: " + this.glVersion);
event.right.add(6 + offset, "CPU Cores: " + Runtime.getRuntime().availableProcessors());
event.right.add(7 + offset, "OS: " + this.osName + " (" + this.osVersion + ", " + this.osArch + ")");
if (DebugConfig.renderDebug) {
event.right.add(8 + offset, "renderDebugMode: " + HodgepodgeClient.renderDebugMode);
event.right.add(8 + offset, null); // Empty Line
if (DebugConfig.renderDebug) {
event.right.add(9 + offset, "renderDebugMode: " + HodgepodgeClient.renderDebugMode);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@ public static void postInit() {

MinecraftForge.EVENT_BUS.register(new ReloadSoundsGui());

if (TweaksConfig.addSystemInfo) {
MinecraftForge.EVENT_BUS.register(DebugScreenHandler.INSTANCE);
}
MinecraftForge.EVENT_BUS.register(DebugScreenHandler.INSTANCE);

if (DebugConfig.showChunkGenDebug || !FMLForgePlugin.RUNTIME_DEOBF) {
MinecraftForge.EVENT_BUS.register(ChunkGenDebugHandler.INSTANCE);
}

MinecraftForge.EVENT_BUS.register(new AllocationRateHUD(true));
ClientCommandHandler.instance.registerCommand(new AllocationsCommand());
ClientCommandHandler.instance.registerCommand(new DumpTextureAtlasCommand());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public int getRequiredPermissionLevel() {
@Override
public void processCommand(ICommandSender sender, String[] args) {
if (handler == null) {
handler = new AllocationRateHUD(false);
handler = new AllocationRateHUD();
MinecraftForge.EVENT_BUS.register(handler);
} else {
MinecraftForge.EVENT_BUS.unregister(handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,8 @@ public class TweaksConfig {
@Config.Comment("Allow creative tab gui title color via localization key")
@Config.DefaultBoolean(true)
public static boolean creativeTabLocalizationOverrides;

@Config.Comment("Makes the int cache size more readable")
@Config.DefaultBoolean(true)
public static boolean moreReadableIntCacheSize;
}
4 changes: 4 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public enum Mixins implements IMixins {

// spotless:off
// region Vanilla Fixes
HODGEPODGE_F3_INFO(new MixinBuilder()
.addClientMixins("debug.MixinIntCache")
.setApplyIf(() -> TweaksConfig.moreReadableIntCacheSize)
.setPhase(Phase.EARLY)),
FIX_DATAWATCHER_SHARING_OBJECTS_IN_SP(new MixinBuilder()
.addClientMixins("minecraft.MixinDataWatcher_DeepCopyInSP")
.setApplyIf(() -> FixesConfig.deepCopyDataWatcherInSP)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.mitchej123.hodgepodge.mixins.early.debug;

import java.util.List;

import net.minecraft.world.gen.layer.IntCache;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(IntCache.class)
public class MixinIntCache {

@Shadow
private static List freeSmallArrays;

@Shadow
private static List freeLargeArrays;

@Shadow
private static List inUseLargeArrays;

@Shadow
private static List inUseSmallArrays;

/**
* @author Alexdoru
* @reason More readable info
*/
@Overwrite
public static synchronized String getCacheSizes() {
return "IntCache: free (L: " + freeLargeArrays.size()
+ ", S: "
+ freeSmallArrays.size()
+ ") used (L: "
+ inUseLargeArrays.size()
+ ", S: "
+ inUseSmallArrays.size()
+ ")";
}
}
Loading