From 44691f38f14a562a0e651dcc28393095fa31fc36 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 26 Aug 2023 17:57:36 -0500 Subject: [PATCH] fix quality preset cache reset firing too often --- .../distanthorizons/core/config/Config.java | 9 +--- .../RenderCacheConfigEventHandler.java | 49 ++++++++++++++----- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index e15885a01..a64ef8789 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -152,7 +152,6 @@ public class Config + "\n" + "Lowest Quality: " + EMaxHorizontalResolution.CHUNK + "\n" + "Highest Quality: " + EMaxHorizontalResolution.BLOCK) - .addListener(RenderCacheConfigEventHandler.INSTANCE) .setPerformance(EConfigEntryPerformance.MEDIUM) .build(); @@ -173,7 +172,6 @@ public class Config + "Lowest Quality: " + EVerticalQuality.HEIGHT_MAP + "\n" + "Highest Quality: " + EVerticalQuality.EXTREME) .setPerformance(EConfigEntryPerformance.VERY_HIGH) - .addListener(RenderCacheConfigEventHandler.INSTANCE) .build(); public static ConfigEntry ssao = new ConfigEntry.Builder() @@ -200,7 +198,6 @@ public class Config + ETransparency.DISABLED + ": LODs will be opaque. \n" + "") .setPerformance(EConfigEntryPerformance.MEDIUM) - .addListener(RenderCacheConfigEventHandler.INSTANCE) .build(); public static ConfigEntry blocksToIgnore = new ConfigEntry.Builder() @@ -212,7 +209,6 @@ public class Config + EBlocksToAvoid.NON_COLLIDING + ": Only represent solid blocks in the LODs (tall grass, torches, etc. won't count for a LOD's height) \n" + "") .setPerformance(EConfigEntryPerformance.NONE) - .addListener(RenderCacheConfigEventHandler.INSTANCE) .build(); public static ConfigEntry tintWithAvoidedBlocks = new ConfigEntry.Builder() @@ -224,7 +220,6 @@ public class Config + "False: skipped blocks will not change color of surface below them. " + "") .setPerformance(EConfigEntryPerformance.NONE) - .addListener(RenderCacheConfigEventHandler.INSTANCE) .build(); // TODO fixme @@ -532,7 +527,6 @@ public class Config + "0 = black \n" + "1 = normal \n" + "2 = near white") - .addListener(RenderCacheConfigEventHandler.INSTANCE) .build(); public static ConfigEntry saturationMultiplier = new ConfigEntry.Builder() // TODO: Make this a float (the ClassicConfigGUI doesnt support floats) @@ -543,7 +537,6 @@ public class Config + "0 = black and white \n" + "1 = normal \n" + "2 = very saturated") - .addListener(RenderCacheConfigEventHandler.INSTANCE) .build(); public static ConfigEntry enableCaveCulling = new ConfigEntry.Builder() @@ -601,7 +594,6 @@ public class Config + ELodShading.NONE + ": All LOD sides will be rendered with the same brightness. \n" + "") .setPerformance(EConfigEntryPerformance.NONE) - .addListener(RenderCacheConfigEventHandler.INSTANCE) .build(); } @@ -1231,6 +1223,7 @@ public class Config ThreadPresetConfigEventHandler.INSTANCE.setUiOnlyConfigValues(); RenderQualityPresetConfigEventHandler.INSTANCE.setUiOnlyConfigValues(); QuickRenderToggleConfigEventHandler.INSTANCE.setUiOnlyConfigValues(); + RenderCacheConfigEventHandler.getInstance(); } catch (Exception e) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/RenderCacheConfigEventHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/RenderCacheConfigEventHandler.java index 4ad052173..ac3eb4cb1 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/RenderCacheConfigEventHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/RenderCacheConfigEventHandler.java @@ -1,9 +1,12 @@ package com.seibel.distanthorizons.core.config.eventHandlers; import com.seibel.distanthorizons.api.DhApi; +import com.seibel.distanthorizons.api.enums.config.EBlocksToAvoid; import com.seibel.distanthorizons.api.enums.config.ELodShading; import com.seibel.distanthorizons.api.enums.config.EMaxHorizontalResolution; import com.seibel.distanthorizons.api.enums.config.EVerticalQuality; +import com.seibel.distanthorizons.api.enums.rendering.ETransparency; +import com.seibel.distanthorizons.core.config.listeners.ConfigChangeListener; import com.seibel.distanthorizons.core.config.listeners.IConfigListener; import com.seibel.distanthorizons.core.config.Config; @@ -16,28 +19,52 @@ import java.util.TimerTask; * * Note: if additional settings should clear the render cache, add those to this listener, don't create a new listener */ -public class RenderCacheConfigEventHandler implements IConfigListener +public class RenderCacheConfigEventHandler { - public static RenderCacheConfigEventHandler INSTANCE = new RenderCacheConfigEventHandler(); + private static RenderCacheConfigEventHandler INSTANCE; + + + // previous values used to check if a watched setting was actually modified + private final ConfigChangeListener horizontalResolutionChangeListener; + private final ConfigChangeListener verticalQualityChangeListener; + private final ConfigChangeListener transparencyChangeListener; + private final ConfigChangeListener blocksToIgnoreChangeListener; + private final ConfigChangeListener tintWithAvoidedBlocksChangeListener; + + private final ConfigChangeListener brightnessMultiplierChangeListener; + private final ConfigChangeListener saturationMultiplierChangeListener; + private final ConfigChangeListener lodShadingChangeListener; /** how long to wait in milliseconds before applying the config changes */ private static final long TIMEOUT_IN_MS = 4_000L; private Timer cacheClearingTimer; - /** private since we only ever need one handler at a time */ - private RenderCacheConfigEventHandler() { } - - - @Override - public void onConfigValueSet() + public static RenderCacheConfigEventHandler getInstance() { - this.refreshRenderDataAfterTimeout(); + if (INSTANCE == null) + { + INSTANCE = new RenderCacheConfigEventHandler(); + } + + return INSTANCE; } - @Override - public void onUiModify() { /* do nothing, we only care about modified config values */ } + /** private since we only ever need one handler at a time */ + private RenderCacheConfigEventHandler() + { + this.horizontalResolutionChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Graphics.Quality.maxHorizontalResolution, (newValue) -> this.refreshRenderDataAfterTimeout()); + this.verticalQualityChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Graphics.Quality.verticalQuality, (newValue) -> this.refreshRenderDataAfterTimeout()); + this.transparencyChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Graphics.Quality.transparency, (newValue) -> this.refreshRenderDataAfterTimeout()); + this.blocksToIgnoreChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Graphics.Quality.blocksToIgnore, (newValue) -> this.refreshRenderDataAfterTimeout()); + this.tintWithAvoidedBlocksChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Graphics.Quality.tintWithAvoidedBlocks, (newValue) -> this.refreshRenderDataAfterTimeout()); + + this.brightnessMultiplierChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Graphics.AdvancedGraphics.brightnessMultiplier, (newValue) -> this.refreshRenderDataAfterTimeout()); + this.saturationMultiplierChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Graphics.AdvancedGraphics.saturationMultiplier, (newValue) -> this.refreshRenderDataAfterTimeout()); + this.lodShadingChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Graphics.AdvancedGraphics.lodShading, (newValue) -> this.refreshRenderDataAfterTimeout()); + + } /** Calling this method multiple times will reset the timer */