From d7377990151bfffea2acb3db066be94d3269d16e Mon Sep 17 00:00:00 2001 From: LostLuma Date: Mon, 3 Jun 2024 12:37:50 +0200 Subject: [PATCH] Fix remaining issues from config target FPS refactor Ref: https://github.com/juliand665/Dynamic-FPS/pull/188 --- .../main/java/dynamic_fps/impl/DynamicFPSMod.java | 13 ++++++++----- .../impl/mixin/DebugScreenOverlayMixin.java | 5 ++++- .../java/dynamic_fps/impl/mixin/MinecraftMixin.java | 9 +++------ .../java/dynamic_fps/impl/mixin/WindowMixin.java | 12 ++++++++---- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java b/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java index 4057a459..6a64e27a 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java @@ -257,11 +257,14 @@ private static void checkForStateChanges0() { private static boolean checkForRender(long timeSinceLastRender) { int frameRateTarget = targetFrameRate(); - // Special frame rate target - // 0 -> disable rendering - // -1 -> uncapped frame rate - if (frameRateTarget <= 0) { - return frameRateTarget == -1; + // Disable all rendering + if (frameRateTarget == 0) { + return false; + } + + // Disable frame rate limiting + if (frameRateTarget == Constants.NO_FRAME_RATE_LIMIT) { + return true; } // Render one more frame before diff --git a/platforms/common/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java b/platforms/common/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java index 8c898105..dbd2fc0d 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.Locale; +import dynamic_fps.impl.Constants; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -29,9 +30,11 @@ private List getGameInformation(List result) { if (status != PowerState.FOCUSED) { int target = DynamicFPSMod.targetFrameRate(); + String fps = target == Constants.NO_FRAME_RATE_LIMIT ? "inf" : Integer.toString(target); + result.add( 2, - this.format("§c[Dynamic FPS] FPS: %s P: %s§r", target, status.toString().toLowerCase()) + this.format("§c[Dynamic FPS] FPS: %s P: %s§r", fps, status.toString().toLowerCase()) ); } } diff --git a/platforms/common/src/main/java/dynamic_fps/impl/mixin/MinecraftMixin.java b/platforms/common/src/main/java/dynamic_fps/impl/mixin/MinecraftMixin.java index c3544a1d..98708263 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/mixin/MinecraftMixin.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/mixin/MinecraftMixin.java @@ -47,17 +47,14 @@ private void getFramerateLimit(CallbackInfoReturnable callbackInfo) { int limit = this.window.getFramerateLimit(); if (DynamicFPSMod.powerState() != PowerState.FOCUSED) { - // Limit may be 260 (uncapped) - if (limit < 60) { - callbackInfo.setReturnValue(limit); - } + callbackInfo.setReturnValue(limit); } else if (DynamicFPSMod.uncapMenuFrameRate()) { if (this.options.enableVsync().get()) { // VSync will regulate to a non-infinite value callbackInfo.setReturnValue(Constants.NO_FRAME_RATE_LIMIT); } else { - // Even though the option "uncaps" the frame rate the max is 250 FPS - // Since otherwise this will just cause coil whine for no real benefit. + // Even though the option "uncaps" the frame rate the limit is 250 FPS. + // Since otherwise this will just cause coil whine with no real benefit callbackInfo.setReturnValue(Math.min(limit, Constants.NO_FRAME_RATE_LIMIT - 10)); } } diff --git a/platforms/common/src/main/java/dynamic_fps/impl/mixin/WindowMixin.java b/platforms/common/src/main/java/dynamic_fps/impl/mixin/WindowMixin.java index 7f7b0ca8..6dfcfd9f 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/mixin/WindowMixin.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/mixin/WindowMixin.java @@ -1,5 +1,6 @@ package dynamic_fps.impl.mixin; +import dynamic_fps.impl.PowerState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,9 +17,12 @@ public class WindowMixin { */ @Inject(method = "getFramerateLimit", at = @At("RETURN"), cancellable = true) private void onGetFramerateLimit(CallbackInfoReturnable callbackInfo) { - // We're currently reducing the frame rate - // Instruct Minecraft to render max 15 FPS - // Going lower here makes resuming feel sluggish - callbackInfo.setReturnValue(Math.max(Math.min(callbackInfo.getReturnValue(), DynamicFPSMod.targetFrameRate()), 15)); + PowerState state = DynamicFPSMod.powerState(); + + if (state != PowerState.FOCUSED) { + // Instruct Minecraft to render a minimum of 15 FPS + // Going lower here makes resuming again feel sluggish + callbackInfo.setReturnValue(Math.max(DynamicFPSMod.targetFrameRate(), 15)); + } } }