Skip to content

Commit

Permalink
Move debug overlay to a new setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Nov 12, 2024
1 parent 09e3e10 commit 37c3139
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class NoxesiumConfig {
public MapLocation mapUiLocation = MapLocation.TOP;
public int minUiFramerate = 30;
public int maxUiFramerate = 120;
public boolean showOptimizationOverlay = false;

/**
* Returns whether experimental performance are enabled in the configuration.
Expand All @@ -59,6 +60,8 @@ public boolean shouldRenderMapsInUi() {
* Whether the experimental performance patches should be used.
*/
public boolean shouldDisableExperimentalPerformancePatches() {
if (ServerRules.DISABLE_UI_OPTIMIZATIONS.getValue()) return true;

if (hasConfiguredPerformancePatches()) {
if (experimentalPatchesHotkey != null) {
return !experimentalPatchesHotkey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ public class NoxesiumOptions {
}
);

private static final OptionInstance<Boolean> optimizationOverlay = OptionInstance.createBoolean(
"noxesium.options.optimization_overlay.name",
OptionInstance.cachedConstantTooltip(Component.translatable("noxesium.options.optimization_overlay.tooltip")),
NoxesiumMod.getInstance().getConfig().showOptimizationOverlay,
(newValue) -> {
NoxesiumMod.getInstance().getConfig().showOptimizationOverlay = newValue;
NoxesiumMod.getInstance().getConfig().save();
}
);

public static OptionInstance<Boolean> experimentalPatches() {
return experimentalPatches;
}
Expand Down Expand Up @@ -161,4 +171,8 @@ public static OptionInstance<Integer> minUiFramerate() {
public static OptionInstance<Integer> maxUiFramerate() {
return maxUiFramerate;
}

public static OptionInstance<Boolean> optimizationOverlay() {
return optimizationOverlay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ public NoxesiumSettingsScreen(Screen screen) {
@Override
protected void addOptions() {
this.list.addSmall(
NoxesiumOptions.fpsOverlay(),
NoxesiumOptions.gameTimeOverlay(),
NoxesiumOptions.dumpIncomingPackets(),
NoxesiumOptions.dumpOutgoingPackets(),
NoxesiumOptions.extendedPacketLogging(),
NoxesiumOptions.playerGlowingKeybinds(),
NoxesiumOptions.qibSystemDebugVisuals()
NoxesiumOptions.fpsOverlay(),
NoxesiumOptions.gameTimeOverlay(),
NoxesiumOptions.dumpIncomingPackets(),
NoxesiumOptions.dumpOutgoingPackets(),
NoxesiumOptions.extendedPacketLogging(),
NoxesiumOptions.playerGlowingKeybinds(),
NoxesiumOptions.qibSystemDebugVisuals()
);
this.list.addBig(NoxesiumOptions.experimentalPatches());
this.list.addSmall(
NoxesiumOptions.minUiFramerate(),
NoxesiumOptions.maxUiFramerate()
NoxesiumOptions.minUiFramerate(),
NoxesiumOptions.maxUiFramerate(),
NoxesiumOptions.optimizationOverlay()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public void add(NoxesiumLayer layer) {
@Override
public void render(GuiGraphics guiGraphics, @NotNull DeltaTracker deltaTracker) {
// If experimental patches are disabled we ignore all custom logic.
if (NoxesiumMod.getInstance().getConfig().shouldDisableExperimentalPerformancePatches() ||
ServerRules.DISABLE_UI_OPTIMIZATIONS.getValue()) {
if (NoxesiumMod.getInstance().getConfig().shouldDisableExperimentalPerformancePatches()) {
// Destroy the state if it exists
if (state != null) state = null;

Expand Down
16 changes: 10 additions & 6 deletions fabric/src/main/java/com/noxcrew/noxesium/mixin/ui/GuiMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.LayeredDraw;
import net.minecraft.client.gui.components.DebugScreenOverlay;
import net.minecraft.client.gui.screens.inventory.MenuAccess;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -27,7 +28,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.ArrayList;
import java.util.Objects;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -84,7 +84,8 @@ public abstract class GuiMixin {
}

// If the experimental patches are on we draw the current UI frame rates and group layouts
if (Objects.equals(NoxesiumConfig.experimentalPatchesHotkey, true)) {
if (NoxesiumMod.getInstance().getConfig().showOptimizationOverlay &&
!NoxesiumMod.getInstance().getConfig().shouldDisableExperimentalPerformancePatches()) {
NoxesiumMod.forEachRenderStateHolder((it) -> {
var stateIn = it.get();
switch (stateIn) {
Expand All @@ -97,10 +98,13 @@ public abstract class GuiMixin {
}
}
case NoxesiumScreenRenderState state -> {
var dynamic = state.dynamic();
var renderFps = dynamic.renderFramerate() >= 260 ? "Unlimited" : dynamic.renderFramerate();
var checkFps = dynamic.updateFramerate();
text.add(Component.literal("§eScreen: §f" + renderFps + " / " + checkFps));
// Only show this if we are currently running the screen optimizations
if (Minecraft.getInstance().screen instanceof MenuAccess<?>) {
var dynamic = state.dynamic();
var renderFps = dynamic.renderFramerate() >= 260 ? "Unlimited" : dynamic.renderFramerate();
var checkFps = dynamic.updateFramerate();
text.add(Component.literal("§eScreen: §f" + renderFps + " / " + checkFps));
}
}
case null, default -> {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.noxcrew.noxesium.mixin.ui;

import com.noxcrew.noxesium.NoxesiumMod;
import com.noxcrew.noxesium.feature.rule.ServerRules;
import com.noxcrew.noxesium.feature.ui.render.screen.ScreenRenderingHolder;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
Expand All @@ -21,9 +20,7 @@ public class ScreenRenderHookMixin {
public void renderScreen(Screen instance, GuiGraphics guiGraphics, int width, int height, float deltaTime) {
// If experimental patches are disabled we ignore all custom logic,
// or if we are not in a GUI menu.
if (!(instance instanceof MenuAccess) ||
NoxesiumMod.getInstance().getConfig().shouldDisableExperimentalPerformancePatches() ||
ServerRules.DISABLE_UI_OPTIMIZATIONS.getValue()) {
if (!(instance instanceof MenuAccess) || NoxesiumMod.getInstance().getConfig().shouldDisableExperimentalPerformancePatches()) {
// Destroy the state if it exists
ScreenRenderingHolder.getInstance().clear();

Expand Down
2 changes: 2 additions & 0 deletions fabric/src/main/resources/assets/noxesium/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"noxesium.options.min_ui_framerate.tooltip": "Sets the lowest framerate at which UI elements are rendered. This controls how quickly the UI will adapt to controls.",
"noxesium.options.max_ui_framerate.name": "Max UI Framerate",
"noxesium.options.max_ui_framerate.tooltip": "Sets the highest framerate at which UI elements are rendered.\n\n§cSetting this to Unlimited has a very high performance impact!",
"noxesium.options.optimization_overlay.name": "UI Optimization Overlay",
"noxesium.options.optimization_overlay.tooltip": "Adds a small overlay that shows debug information about the UI rendering optimizations.",

"noxesium.options.enum.default": "Ask server",
"noxesium.options.enum.true": "Always",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_version=0.106.1+1.21.2
mod_version=2.5.0-SNAPSHOT

# Mod dependencies
sodium = mc1.21.3-0.6.0-beta.4-fabric
sodium = mc1.21.3-0.6.0-beta.5-fabric
modmenu = 12.0.0-beta.1

# Enabled mods
Expand Down

0 comments on commit 37c3139

Please sign in to comment.