Skip to content

Commit b836771

Browse files
committed
Merge branch '1.21/dev' into 1.21/stable
2 parents 37ac836 + c0413b7 commit b836771

23 files changed

Lines changed: 456 additions & 374 deletions

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ val PARCHMENT_VERSION by extra { null }
1414
// https://semver.org/
1515
val MAVEN_GROUP by extra { "me.flashyreese.mods" }
1616
val ARCHIVE_NAME by extra { "sodium-extra" }
17-
val MOD_VERSION by extra { "0.6.5" }
17+
val MOD_VERSION by extra { "0.6.6" }
1818
val SODIUM_VERSION by extra { "mc1.21.6-0.6.13" }
1919

2020
allprojects {

common/src/main/java/me/flashyreese/mods/sodiumextra/client/ClientTickHandler.java

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package me.flashyreese.mods.sodiumextra.client;
2+
3+
import java.util.ArrayDeque;
4+
import java.util.Comparator;
5+
import java.util.Deque;
6+
import java.util.List;
7+
8+
public class FrameCounter {
9+
private static final FrameCounter INSTANCE = new FrameCounter();
10+
private final Deque<FrameSample> samples = new ArrayDeque<>();
11+
private final long smoothWindow = 500_000_000L; // 0.5 seconds in nanoseconds
12+
private final long windowNanos = 5_000_000_000L; // 5 seconds in nanoseconds
13+
private final long updateIntervalNanos = 500_000_000L; // 0.5 seconds in nanoseconds
14+
private long lastFrameTime = -1;
15+
private long lastUpdateTime = 0;
16+
private double cachedSmoothFps = 0;
17+
private double cachedAverageFps = 0;
18+
private double cachedOnePercentLowFps = 0;
19+
private double cachedPointOnePercentLowFps = 0;
20+
21+
public static FrameCounter getInstance() {
22+
return FrameCounter.INSTANCE;
23+
}
24+
25+
public synchronized void onFrame() {
26+
long now = System.nanoTime();
27+
28+
// Record new frame delta
29+
if (this.lastFrameTime != -1) {
30+
long delta = now - this.lastFrameTime;
31+
this.samples.addLast(new FrameSample(now, delta));
32+
}
33+
this.lastFrameTime = now;
34+
35+
// Trim old samples
36+
while (!this.samples.isEmpty() && now - this.samples.peekFirst().timestamp > this.windowNanos) {
37+
this.samples.removeFirst();
38+
}
39+
40+
// Throttle stat computation
41+
if (now - this.lastUpdateTime >= this.updateIntervalNanos) {
42+
this.lastUpdateTime = now;
43+
if (!this.samples.isEmpty()) {
44+
long totalNanos = this.samples.stream().mapToLong(s -> s.deltaNanos).sum();
45+
this.cachedAverageFps = (double) (this.samples.size() * 1_000_000_000L) / totalNanos;
46+
this.cachedOnePercentLowFps = this.computePercentileLow(1.0);
47+
this.cachedPointOnePercentLowFps = this.computePercentileLow(0.1);
48+
this.cachedSmoothFps = this.computeSmoothFpsFromRecentFrames(now);
49+
} else {
50+
this.cachedAverageFps = this.cachedOnePercentLowFps = this.cachedPointOnePercentLowFps = this.cachedSmoothFps = 0;
51+
}
52+
}
53+
}
54+
55+
private double computeSmoothFpsFromRecentFrames(long now) {
56+
List<Long> recent = this.samples.stream()
57+
.filter(s -> now - s.timestamp <= this.smoothWindow)
58+
.map(s -> s.deltaNanos)
59+
.toList();
60+
61+
if (recent.isEmpty()) return 0;
62+
63+
double avgDelta = recent.stream().mapToLong(Long::longValue).average().orElse(0);
64+
return 1_000_000_000.0 / avgDelta;
65+
}
66+
67+
public synchronized int getSmoothFps() {
68+
return (int) Math.round(this.cachedSmoothFps);
69+
}
70+
71+
public synchronized int getAverageFps() {
72+
return (int) Math.round(this.cachedAverageFps);
73+
}
74+
75+
public synchronized int getOnePercentLowFps() {
76+
return (int) Math.round(this.cachedOnePercentLowFps);
77+
}
78+
79+
public synchronized int getPointOnePercentLowFps() {
80+
return (int) Math.round(this.cachedPointOnePercentLowFps);
81+
}
82+
83+
private double computePercentileLow(double percent) {
84+
if (this.samples.isEmpty()) return 0;
85+
List<Long> deltas = this.samples.stream()
86+
.map(s -> s.deltaNanos)
87+
.sorted(Comparator.reverseOrder()) // slowest frames first
88+
.toList();
89+
90+
int count = Math.max(1, (int) Math.ceil(deltas.size() * (percent / 100.0)));
91+
long sum = 0;
92+
for (int i = 0; i < count; i++) sum += deltas.get(i);
93+
double avgDelta = sum / (double) count;
94+
return 1_000_000_000.0 / avgDelta;
95+
}
96+
97+
private record FrameSample(long timestamp, long deltaNanos) {
98+
}
99+
}

common/src/main/java/me/flashyreese/mods/sodiumextra/client/SodiumExtraClientMod.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import org.slf4j.LoggerFactory;
1212

1313
public class SodiumExtraClientMod {
14-
15-
private static final ClientTickHandler clientTickHandler = new ClientTickHandler();
1614
private static SodiumExtraGameOptions CONFIG;
1715
private static CaffeineConfig MIXIN_CONFIG;
1816
private static Logger LOGGER;
@@ -44,13 +42,12 @@ public static CaffeineConfig mixinConfig() {
4442
.addMixinOption("cloud", true)
4543
.addMixinOption("compat", true, false)
4644
.addMixinOption("fog", true)
47-
.addMixinOption("fog_falloff", true)
45+
.addMixinOption("fps", true)
4846
.addMixinOption("gui", true)
4947
.addMixinOption("instant_sneak", true)
5048
.addMixinOption("light_updates", true)
5149
.addMixinOption("optimizations", true)
5250
.addMixinOption("optimizations.beacon_beam_rendering", true)
53-
.addMixinOption("optimizations.draw_helpers", false)
5451
.addMixinOption("particle", true)
5552
.addMixinOption("prevent_shaders", true)
5653
.addMixinOption("reduce_resolution_on_mac", true)
@@ -79,10 +76,6 @@ public static CaffeineConfig mixinConfig() {
7976
return MIXIN_CONFIG;
8077
}
8178

82-
public static ClientTickHandler getClientTickHandler() {
83-
return clientTickHandler;
84-
}
85-
8679
private static SodiumExtraGameOptions loadConfig() {
8780
return SodiumExtraGameOptions.load(PlatformRuntimeInformation.getInstance().getConfigDirectory().resolve("sodium-extra-options.json").toFile());
8881
}
@@ -91,7 +84,6 @@ public static void onTick(Minecraft client) {
9184
if (hud == null) {
9285
hud = new SodiumExtraHud();
9386
}
94-
clientTickHandler.onClientTick(client);
9587
hud.onStartTick(client);
9688
}
9789

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package me.flashyreese.mods.sodiumextra.client.fog;
2+
3+
import net.minecraft.client.DeltaTracker;
4+
import net.minecraft.client.multiplayer.ClientLevel;
5+
import net.minecraft.client.renderer.fog.FogData;
6+
import net.minecraft.core.BlockPos;
7+
import net.minecraft.world.entity.Entity;
8+
import net.minecraft.world.level.material.FogType;
9+
10+
public interface FogEnvironmentExtended {
11+
void sodium_extra$applyFogSettings(FogType fogType, FogData fogData, Entity entity, BlockPos blockPos, ClientLevel clientLevel, float viewDistance, DeltaTracker deltaTracker);
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package me.flashyreese.mods.sodiumextra.client.gui;
2+
3+
public class FogTypeConfig {
4+
public boolean enable;
5+
public int environmentStartMultiplier;
6+
public int environmentEndMultiplier;
7+
public int renderDistanceStartMultiplier;
8+
public int renderDistanceEndMultiplier;
9+
public int skyEndMultiplier;
10+
public int cloudEndMultiplier;
11+
12+
public FogTypeConfig() {
13+
this.enable = true;
14+
this.environmentStartMultiplier = 100;
15+
this.environmentEndMultiplier = 100;
16+
this.renderDistanceStartMultiplier = 100;
17+
this.renderDistanceEndMultiplier = 100;
18+
this.skyEndMultiplier = 100;
19+
this.cloudEndMultiplier = 100;
20+
}
21+
}

0 commit comments

Comments
 (0)