Cleanup dynamic sounds patch, bump eviction time to 5 minutes

This commit is contained in:
embeddedt 2023-10-07 18:44:33 -04:00
parent 803aaba204
commit bf6979e45b
2 changed files with 7 additions and 8 deletions

View File

@ -24,13 +24,12 @@ public abstract class SoundBufferLibraryMixin {
private static final boolean debugDynamicSoundLoading = Boolean.getBoolean("modernfix.debugDynamicSoundLoading");
@Shadow @Final @Mutable
private Map<ResourceLocation, CompletableFuture<SoundBuffer>> cache =
CacheBuilder.newBuilder()
.expireAfterAccess(DynamicSoundHelpers.MAX_SOUND_LIFETIME_SECS, TimeUnit.SECONDS)
// Excessive use of type hinting due to it assuming Object as the broadest correct type
.<ResourceLocation, CompletableFuture<SoundBuffer>>removalListener(this::onSoundRemoval)
.<ResourceLocation, CompletableFuture<SoundBuffer>>build()
.asMap();
private Map<ResourceLocation, CompletableFuture<SoundBuffer>> cache = CacheBuilder.newBuilder()
.expireAfterAccess(DynamicSoundHelpers.MAX_SOUND_LIFETIME_SECS, TimeUnit.SECONDS)
// Excessive use of type hinting due to it assuming Object as the broadest correct type
.<ResourceLocation, CompletableFuture<SoundBuffer>>removalListener(this::onSoundRemoval)
.build()
.asMap();
private <K extends ResourceLocation, V extends CompletableFuture<SoundBuffer>> void onSoundRemoval(RemovalNotification<K, V> notification) {
notification.getValue().thenAccept(SoundBuffer::discardAlBuffer);

View File

@ -4,5 +4,5 @@ public class DynamicSoundHelpers {
/**
* The duration until a sound is eligible for eviction if unused.
*/
public static final int MAX_SOUND_LIFETIME_SECS = 120;
public static final int MAX_SOUND_LIFETIME_SECS = 300;
}