diff options
author | makamys <makamys@outlook.com> | 2022-07-15 18:35:26 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-07-15 19:53:08 +0200 |
commit | 0c9070cf93b660b29b98c0916f319f3f7b3e1583 (patch) | |
tree | 06bf8003db4ddebecfbd2f1d80bf1d4800a85265 /src/main | |
parent | 732bb8807b20c5de832a5a3606d418f38a91e438 (diff) | |
download | Neodymium-0c9070cf93b660b29b98c0916f319f3f7b3e1583.tar.gz Neodymium-0c9070cf93b660b29b98c0916f319f3f7b3e1583.tar.bz2 Neodymium-0c9070cf93b660b29b98c0916f319f3f7b3e1583.zip |
Add `auto` option to renderFog, which respects GL setting
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/makamys/neodymium/config/Config.java | 63 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/renderer/NeoRenderer.java | 15 |
2 files changed, 73 insertions, 5 deletions
diff --git a/src/main/java/makamys/neodymium/config/Config.java b/src/main/java/makamys/neodymium/config/Config.java index a724c98..c582033 100644 --- a/src/main/java/makamys/neodymium/config/Config.java +++ b/src/main/java/makamys/neodymium/config/Config.java @@ -22,15 +22,20 @@ import java.nio.file.WatchEvent; import java.nio.file.WatchKey; import java.nio.file.WatchService; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; +import org.apache.commons.lang3.EnumUtils; import org.lwjgl.input.Keyboard; import cpw.mods.fml.client.config.IConfigElement; import makamys.neodymium.Neodymium; import net.minecraft.launchwrapper.Launch; +import net.minecraftforge.common.config.ConfigCategory; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; +import net.minecraftforge.common.config.Property.Type; public class Config { @@ -57,8 +62,8 @@ public class Config { @NeedsReload @ConfigInt(cat="render", def=512, min=1, max=Integer.MAX_VALUE, com="VRAM buffer size (MB). 512 seems to be a good value on Normal render distance. Increase this if you encounter warnings about the VRAM getting full. Does not affect RAM usage.") public static int VRAMSize; - @ConfigBoolean(cat="render", def=true, com="Render fog? Slightly reduces framerate.") - public static boolean renderFog; + @ConfigEnum(cat="render", def="auto", clazz=AutomatableBoolean.class, com="Render fog? Slightly reduces framerate. `auto` means the OpenGL setting will be respected (as set by mods like OptiFine).\nValid values: true, false, auto") + public static AutomatableBoolean renderFog; @ConfigBoolean(cat="misc", def=true, com="Replace splash that says 'OpenGL 1.2!' with 'OpenGL 3.3!'. Just for fun.") public static boolean replaceOpenGLSplash; @@ -124,6 +129,7 @@ public class Config { NeedsReload needsReload = null; ConfigBoolean configBoolean = null; ConfigInt configInt = null; + ConfigEnum configEnum = null; for(Annotation an : field.getAnnotations()) { if(an instanceof NeedsReload) { @@ -132,10 +138,12 @@ public class Config { configInt = (ConfigInt) an; } else if(an instanceof ConfigBoolean) { configBoolean = (ConfigBoolean) an; + } else if(an instanceof ConfigEnum) { + configEnum = (ConfigEnum) an; } } - if(configBoolean == null && configInt == null) continue; + if(configBoolean == null && configInt == null && configEnum == null) continue; Object currentValue = null; Object newValue = null; @@ -151,6 +159,40 @@ public class Config { newValue = config.getBoolean(field.getName(), configBoolean.cat(), configBoolean.def(), configBoolean.com()); } else if(configInt != null) { newValue = config.getInt(field.getName(), configInt.cat(), configInt.def(), configInt.min(), configInt.max(), configInt.com()); + } else if(configEnum != null) { + boolean lowerCase = true; + + Class<? extends Enum> configClass = configEnum.clazz(); + Map<String, ? extends Enum> enumMap = EnumUtils.getEnumMap(configClass); + String[] valuesStrUpper = (String[])enumMap.keySet().stream().toArray(String[]::new); + String[] valuesStr = Arrays.stream(valuesStrUpper).map(s -> lowerCase ? s.toLowerCase() : s).toArray(String[]::new); + + // allow upgrading boolean to string list + ConfigCategory cat = config.getCategory(configEnum.cat()); + Property oldProp = cat.get(field.getName()); + String oldVal = null; + if(oldProp != null && oldProp.getType() != Type.STRING) { + oldVal = oldProp.getString(); + cat.remove(field.getName()); + } + + String newValueStr = config.getString(field.getName(), configEnum.cat(), + lowerCase ? configEnum.def().toLowerCase() : configEnum.def().toUpperCase(), configEnum.com(), valuesStr); + if(oldVal != null) { + newValueStr = oldVal; + } + if(!enumMap.containsKey(newValueStr.toUpperCase())) { + newValueStr = configEnum.def().toUpperCase(); + if(lowerCase) { + newValueStr = newValueStr.toLowerCase(); + } + } + newValue = enumMap.get(newValueStr.toUpperCase()); + + Property newProp = cat.get(field.getName()); + if(!newProp.getString().equals(newValueStr)) { + newProp.set(newValueStr); + } } if(needsReload != null && !newValue.equals(currentValue)) { @@ -234,8 +276,23 @@ public class Config { } + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + public static @interface ConfigEnum { + + String cat(); + String def(); + String com() default ""; + Class<? extends Enum> clazz(); + + } + public static class ReloadInfo { public boolean needReload; } + public static enum AutomatableBoolean { + FALSE, TRUE, AUTO + } + } diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index bda5c8f..4fe459c 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -207,7 +207,7 @@ public class NeoRenderer { private boolean shouldRenderMesh(Mesh mesh) { if((Config.maxMeshesPerFrame == -1 || renderedMeshes < Config.maxMeshesPerFrame)) { - if((!Config.renderFog && !Config.fogOcclusionWithoutFog) + if((!isFogEnabled() && !Config.fogOcclusionWithoutFog) || Config.fogOcclusion == !Config.fogOcclusion || mesh.distSq( eyePosX / 16.0, @@ -606,7 +606,18 @@ public class NeoRenderer { } private int getShaderProgram(int pass) { - return ((forceRenderFog || Config.renderFog) ? shaderProgramsFog : shaderProgramsNoFog)[pass]; + return ((forceRenderFog || isFogEnabled()) ? shaderProgramsFog : shaderProgramsNoFog)[pass]; + } + + private static boolean isFogEnabled() { + switch(Config.renderFog) { + case TRUE: + return true; + case FALSE: + return false; + default: + return GL11.glIsEnabled(GL11.GL_FOG); + } } private boolean shouldRenderInWorld(World world) { |