-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to disable the menu FPS limit
- Loading branch information
Showing
6 changed files
with
79 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,61 @@ | ||
package dynamic_fps.impl.mixin; | ||
|
||
import com.mojang.blaze3d.platform.Window; | ||
import dynamic_fps.impl.DynamicFPSMod; | ||
import dynamic_fps.impl.PowerState; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.Options; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.mojang.blaze3d.platform.Window; | ||
|
||
import dynamic_fps.impl.DynamicFPSMod; | ||
import net.minecraft.client.Minecraft; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(Minecraft.class) | ||
public class MinecraftMixin { | ||
@Shadow | ||
@Final | ||
private Window window; | ||
|
||
@Shadow | ||
@Final | ||
public Options options; | ||
|
||
// Minecraft considers limits >=260 as infinite | ||
private static final int NO_FRAME_RATE_LIMIT = 260; | ||
|
||
@Inject(method = "<init>", at = @At("TAIL")) | ||
private void onInit(CallbackInfo callbackInfo) { | ||
DynamicFPSMod.setWindow(this.window.window); | ||
} | ||
|
||
/* | ||
@Inject(method = "setScreen", at = @At("TAIL")) | ||
private void onSetScreen(CallbackInfo callbackInfo) { | ||
DynamicFPSMod.onStatusChanged(); | ||
/** | ||
* Conditionally bypasses the main menu frame rate limit. | ||
* | ||
* This is done in two cases: | ||
* - The window is active, and the user wants to uncap the frame rate | ||
* - The window is inactive, and the current FPS limit should be lower | ||
*/ | ||
@Inject(method = "getFramerateLimit", at = @At(value = "CONSTANT", args = "intValue=60"), cancellable = true) | ||
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); | ||
} | ||
} else if (DynamicFPSMod.uncapMenuFrameRate()) { | ||
if (this.options.enableVsync().get()) { | ||
// VSync will regulate to a non-infinite value | ||
callbackInfo.setReturnValue(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. | ||
callbackInfo.setReturnValue(Math.min(limit, NO_FRAME_RATE_LIMIT - 10)); | ||
} | ||
} | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters