Skip to content

Commit 0967e68

Browse files
Use metric data to calculate fps
1 parent 54babbd commit 0967e68

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/main/java/io/github/ultimateboomer/resolutioncontrol/ResolutionControlMod.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ public void onInitialize() {
105105
});
106106

107107
ClientTickEvents.END_CLIENT_TICK.register(client -> {
108+
// long frametime = client.metricsData.getSamples()[0];
109+
// if (frametime > 0) {
110+
// System.out.println(1_000_000_000 / frametime);
111+
// }
112+
108113
if (ConfigHandler.instance.getConfig().enableDynamicResolution && client.world != null
109114
&& getWindow().getX() != -32000) {
110115
DynamicResolutionHandler.INSTANCE.tick();

src/main/java/io/github/ultimateboomer/resolutioncontrol/util/DynamicResolutionHandler.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import net.minecraft.client.gl.Framebuffer;
99
import net.minecraft.text.LiteralText;
1010

11-
import java.util.Collection;
12-
import java.util.HashMap;
13-
import java.util.List;
14-
import java.util.Map;
11+
import java.util.*;
1512

1613
public class DynamicResolutionHandler {
1714
public static final DynamicResolutionHandler INSTANCE = new DynamicResolutionHandler();
@@ -40,7 +37,7 @@ private DynamicResolutionHandler() {
4037
public void tick() {
4138
timer++;
4239

43-
if (timer > 20) {
40+
if (timer > 5) {
4441
timer = 0;
4542
update();
4643
}
@@ -49,7 +46,12 @@ public void tick() {
4946
private void update() {
5047
MinecraftClient client = MinecraftClient.getInstance();
5148

52-
int fps = MinecraftClient.currentFps;
49+
final int smoothAmount = 10;
50+
long accumulatedFrameTime =
51+
Arrays.stream(client.metricsData.getSamples()).limit(smoothAmount).sum();
52+
53+
double fps = 1_000_000_000.0 / accumulatedFrameTime * smoothAmount;
54+
System.out.println(fps);
5355

5456
if (fps > 80) {
5557
setCurrentScale(Math.min(currentScale + 1, scales.size() - 1));

0 commit comments

Comments
 (0)