Skip to content
Open
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 @@ -38,6 +38,8 @@
import org.jspecify.annotations.Nullable;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -304,7 +306,9 @@ private OptionPageBuilder buildGeneralPage(ConfigBuilder builder) {
.setName(Component.translatable("options.framerateLimit"))
.setTooltip(Component.translatable("sodium.options.fps_limit.tooltip"))
.setValueFormatter(ControlValueFormatterImpls.fpsLimit())
.setRange(10, 260, 10)
.setValidatorProvider(
(state) -> new Range(10, this.getMaxFramerateLimit(), 10),
ConfigState.UPDATE_ON_REBUILD, ConfigState.UPDATE_ON_APPLY)
.setDefaultValue(60)
.setBinding(this.vanillaOpts.framerateLimit()::set, this.vanillaOpts.framerateLimit()::get)
)
Expand Down Expand Up @@ -346,9 +350,36 @@ private OptionPageBuilder buildGeneralPage(ConfigBuilder builder) {
.setDefaultValue(PreferredGraphicsApi.DEFAULT)
.setFlags(OptionFlag.REQUIRES_GAME_RESTART)
.setBinding((value) -> this.vanillaOpts.preferredGraphicsBackend().set(value), () -> this.vanillaOpts.preferredGraphicsBackend().get())));

Comment thread
douira marked this conversation as resolved.
return generalPage;
}

/**
* this computes an appropriate maximum for the framerate limit slider based on the current
* monitor's refresh rate, so users on high-refresh-rate displays aren't capped at 260
* + falls back to the vanilla default max if the window/monitor context isn't available yet
* (e.g. during early config building).
*/
private int getMaxFramerateLimit() {
int monitorRefreshRate = 60;
try {
if (this.window != null){
long windowHandle = this.window.handle();
long monitorHandle = GLFW.glfwGetWindowMonitor(windowHandle);
Comment thread
douira marked this conversation as resolved.
if (monitorHandle == 0L) {
monitorHandle = GLFW.glfwGetPrimaryMonitor();
}
GLFWVidMode vidMode = GLFW.glfwGetVideoMode(monitorHandle);
if (vidMode != null) {
monitorRefreshRate = vidMode.refreshRate();
}
}
} catch (Exception e) {
// fallback if window/monitor context is unavailable
}
return Math.max(260, ((monitorRefreshRate + 9) / 10) * 10 + 10);
}

private OptionPageBuilder buildQualityPage(ConfigBuilder builder) {
var qualityPage = builder.createOptionPage().setName(Component.translatable("sodium.options.pages.quality"));

Expand Down