Skip to content

Commit

Permalink
Fix remaining issues from config target FPS refactor
Browse files Browse the repository at this point in the history
Ref: #188
  • Loading branch information
LostLuma committed Jun 3, 2024
1 parent 74f929b commit d737799
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,9 +30,11 @@ private List<String> getGameInformation(List<String> 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())
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,14 @@ private void getFramerateLimit(CallbackInfoReturnable<Integer> 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));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,9 +17,12 @@ public class WindowMixin {
*/
@Inject(method = "getFramerateLimit", at = @At("RETURN"), cancellable = true)
private void onGetFramerateLimit(CallbackInfoReturnable<Integer> 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));
}
}
}

0 comments on commit d737799

Please sign in to comment.