Skip to content

Commit 972121f

Browse files
committed
Merge 1.20 into 1.20.2
2 parents 93554d1 + e537cbe commit 972121f

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.dynamic_sounds;
2+
3+
import com.google.common.cache.CacheBuilder;
4+
import com.google.common.cache.RemovalNotification;
5+
import com.mojang.blaze3d.audio.SoundBuffer;
6+
import net.minecraft.client.sounds.SoundBufferLibrary;
7+
import net.minecraft.resources.ResourceLocation;
8+
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
9+
import org.embeddedt.modernfix.dynamicresources.DynamicSoundHelpers;
10+
import org.embeddedt.modernfix.ModernFix;
11+
import org.spongepowered.asm.mixin.Final;
12+
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.Mutable;
14+
import org.spongepowered.asm.mixin.Shadow;
15+
16+
import java.util.concurrent.CompletableFuture;
17+
import java.util.concurrent.TimeUnit;
18+
import java.util.Map;
19+
20+
@Mixin(SoundBufferLibrary.class)
21+
@ClientOnlyMixin
22+
public abstract class SoundBufferLibraryMixin {
23+
24+
private static final boolean debugDynamicSoundLoading = Boolean.getBoolean("modernfix.debugDynamicSoundLoading");
25+
26+
@Shadow @Final @Mutable
27+
private Map<ResourceLocation, CompletableFuture<SoundBuffer>> cache = CacheBuilder.newBuilder()
28+
.expireAfterAccess(DynamicSoundHelpers.MAX_SOUND_LIFETIME_SECS, TimeUnit.SECONDS)
29+
// Excessive use of type hinting due to it assuming Object as the broadest correct type
30+
.<ResourceLocation, CompletableFuture<SoundBuffer>>removalListener(this::onSoundRemoval)
31+
.build()
32+
.asMap();
33+
34+
private <K extends ResourceLocation, V extends CompletableFuture<SoundBuffer>> void onSoundRemoval(RemovalNotification<K, V> notification) {
35+
notification.getValue().thenAccept(SoundBuffer::discardAlBuffer);
36+
if(debugDynamicSoundLoading) {
37+
K k = notification.getKey();
38+
if(k == null)
39+
return;
40+
ModernFix.LOGGER.warn("Evicted sound {}", k);
41+
}
42+
}
43+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.embeddedt.modernfix.dynamicresources;
2+
3+
public class DynamicSoundHelpers {
4+
/**
5+
* The duration until a sound is eligible for eviction if unused.
6+
*/
7+
public static final int MAX_SOUND_LIFETIME_SECS = 300;
8+
}

common/src/main/resources/assets/modernfix/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"modernfix.option.mixin.perf.deduplicate_location": "All versions, but disabled by default due to load time impact. Deduplicates resource location namespaces and paths. This saves RAM but also increases the cost of constructing a new `ResourceLocation` by quite a bit.",
4343
"modernfix.option.mixin.perf.dynamic_dfu": "All versions. Modifies DFU initialization to happen the first time something needs to be upgraded. This sounds similar to LazyDFU but is distinctly implemented, as it avoids loading *any* DFU classes/data structures, while LazyDFU only disables rule optimization. Essentially, this option is a safer version of DataFixerSlayer as it will still load DFU when needed.\n\nYou should typically continue to use LazyDFU even with this option enabled, as otherwise DFU rule optimization will cause lag.",
4444
"modernfix.option.mixin.perf.dynamic_resources": "All versions. See https://github.com/embeddedt/ModernFix/wiki/Dynamic-Resources-FAQ.",
45+
"modernfix.option.mixin.perf.dynamic_sounds": "All versions. Allows the game to unload sounds, instead of sounds indefinitely persisting after being loaded.",
4546
"modernfix.option.mixin.perf.dynamic_structure_manager": "All versions. Allows the game to unload structure files after generation concludes instead of keeping them loaded forever.",
4647
"modernfix.option.mixin.perf.fast_registry_validation": "All versions. Forge needlessly looks up a method via reflection every single time a registry is validated. This patch simply caches the returned value since it will be the same every time.",
4748
"modernfix.option.mixin.perf.faster_font_loading": "All versions. Optimizes the font renderer to load fonts faster, speeding up resource reload.",

0 commit comments

Comments
 (0)