diff options
8 files changed, 112 insertions, 93 deletions
diff --git a/src/main/java/makamys/neodymium/Config.java b/src/main/java/makamys/neodymium/Config.java new file mode 100644 index 0000000..05cf4cc --- /dev/null +++ b/src/main/java/makamys/neodymium/Config.java @@ -0,0 +1,81 @@ +package makamys.neodymium; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import org.lwjgl.input.Keyboard; + +import net.minecraftforge.common.config.Configuration; + +public class Config { + + public static boolean enabled; + public static int chunkLoadsPerTick; + public static List<Class<?>> blockClassBlacklist; + public static double fogStart; + public static double fogEnd; + public static double farPlaneDistanceMultiplier; + public static float maxSimpleMeshHeight; + public static boolean forceVanillaBiomeTemperature; + public static boolean hideUnderVanillaChunks; + public static boolean disableChunkMeshes; + public static boolean disableSimpleMeshes; + public static boolean saveMeshes; + public static boolean optimizeChunkMeshes; + public static int maxMeshesPerFrame; + public static int sortFrequency; + public static int gcRate; + public static int VRAMSize; + public static int debugPrefix; + public static int debugInfoStartY; + + static File configFile; + + public static void reloadConfig() { + Configuration config = new Configuration(configFile); + + config.load(); + enabled = config.get("General", "enabled", true).getBoolean(); + chunkLoadsPerTick = config.get("General", "chunkLoadsPerTick", 64).getInt(); + blockClassBlacklist = Arrays.stream(config.get("General", "blockClassBlacklist", "net.minecraft.block.BlockRotatedPillar;biomesoplenty.common.blocks.BlockBOPLog;gregapi.block.multitileentity.MultiTileEntityBlock").getString().split(";")) + .map(className -> { + try { + return Class.forName(className); + } catch (ClassNotFoundException e) { + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + fogStart = config.get("Fog", "fogStart", "0.4").getDouble(); + fogEnd = config.get("Fog", "fogEnd", "0.8").getDouble(); + farPlaneDistanceMultiplier = config.get("Fog", "farPlaneDistanceMultiplier", "1.0").getDouble(); + + maxSimpleMeshHeight = (float)config.get("Debug", "maxSimpleMeshHeight", 1000.0).getDouble(); + + forceVanillaBiomeTemperature = config.get("Simple mesh generation", "forceVanillaBiomeTemperature", true).getBoolean(); + + hideUnderVanillaChunks = config.getBoolean("hideUnderVanillaChunks", "render", true, ""); + disableChunkMeshes = config.getBoolean("disableChunkMeshes", "render", true, ""); + disableSimpleMeshes = config.getBoolean("disableSimpleMeshes", "render", false, ""); + optimizeChunkMeshes = config.getBoolean("optimizeChunkMeshes", "render", true, ""); + saveMeshes = config.getBoolean("saveMeshes", "render", false, ""); + maxMeshesPerFrame = config.getInt("maxMeshesPerFrame", "render", -1, -1, Integer.MAX_VALUE, ""); + sortFrequency = config.getInt("sortFrequency", "render", 1, 1, Integer.MAX_VALUE, ""); + gcRate = config.getInt("gcRate", "render", 1, 1, Integer.MAX_VALUE, "Maximum number of meshes to relocate each frame."); + VRAMSize = config.getInt("VRAMSize", "render", 1024, 1, Integer.MAX_VALUE, "VRAM buffer size (MB)."); + enableFog = config.getBoolean("enableFog", "render", true, ""); + debugPrefix = config.getInt("debugPrefix", "debug", Keyboard.KEY_F4, -1, Integer.MAX_VALUE, "This key has to be held down while pressing the debug keybinds. LWJGL keycode. Setting this to 0 will make the keybinds usable without holding anything else down. Setting this to -1 will disable debug keybinds entirely."); + debugInfoStartY = config.getInt("debugInfoStartY", "debug", 80, -1, Integer.MAX_VALUE, "The Y position of the first line of the debug info in the F3 overlay. Set this to -1 to disable showing that info."); + + if(config.hasChanged()) { + config.save(); + } + } + + public static boolean enableFog; + +} diff --git a/src/main/java/makamys/neodymium/Neodymium.java b/src/main/java/makamys/neodymium/Neodymium.java index 85b34ca..7ed198d 100644 --- a/src/main/java/makamys/neodymium/Neodymium.java +++ b/src/main/java/makamys/neodymium/Neodymium.java @@ -3,7 +3,6 @@ package makamys.neodymium; import java.io.File; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; -import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -32,7 +31,6 @@ import net.minecraftforge.client.event.EntityViewRenderEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.config.Configuration; import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.WorldEvent; @@ -46,80 +44,15 @@ public class Neodymium public static NeoRenderer renderer; - public static boolean enabled; - public static int chunkLoadsPerTick; - public static List<Class> blockClassBlacklist; - public static double fogStart; - public static double fogEnd; - public static double farPlaneDistanceMultiplier; - public static float maxSimpleMeshHeight; - public static boolean forceVanillaBiomeTemperature; - public static boolean hideUnderVanillaChunks; - public static boolean disableChunkMeshes; - public static boolean disableSimpleMeshes; - public static boolean saveMeshes; - public static boolean optimizeChunkMeshes; - public static int maxMeshesPerFrame; - public static int sortFrequency; - public static int gcRate; - public static int VRAMSize; - public static int debugPrefix; - public static int debugInfoStartY; - - private File configFile; - public static boolean fogEventWasPosted; public static boolean ofFastRender; - public static boolean enableFog; @EventHandler public void preInit(FMLPreInitializationEvent event) { - configFile = event.getSuggestedConfigurationFile(); - reloadConfig(); - } - - private void reloadConfig() { - Configuration config = new Configuration(configFile); - - config.load(); - enabled = config.get("General", "enabled", true).getBoolean(); - chunkLoadsPerTick = config.get("General", "chunkLoadsPerTick", 64).getInt(); - blockClassBlacklist = Arrays.stream(config.get("General", "blockClassBlacklist", "net.minecraft.block.BlockRotatedPillar;biomesoplenty.common.blocks.BlockBOPLog;gregapi.block.multitileentity.MultiTileEntityBlock").getString().split(";")) - .map(className -> { - try { - return Class.forName(className); - } catch (ClassNotFoundException e) { - return null; - } - }) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - fogStart = config.get("Fog", "fogStart", "0.4").getDouble(); - fogEnd = config.get("Fog", "fogEnd", "0.8").getDouble(); - farPlaneDistanceMultiplier = config.get("Fog", "farPlaneDistanceMultiplier", "1.0").getDouble(); - - maxSimpleMeshHeight = (float)config.get("Debug", "maxSimpleMeshHeight", 1000.0).getDouble(); - - forceVanillaBiomeTemperature = config.get("Simple mesh generation", "forceVanillaBiomeTemperature", true).getBoolean(); - - hideUnderVanillaChunks = config.getBoolean("hideUnderVanillaChunks", "render", true, ""); - disableChunkMeshes = config.getBoolean("disableChunkMeshes", "render", true, ""); - disableSimpleMeshes = config.getBoolean("disableSimpleMeshes", "render", false, ""); - optimizeChunkMeshes = config.getBoolean("optimizeChunkMeshes", "render", true, ""); - saveMeshes = config.getBoolean("saveMeshes", "render", false, ""); - maxMeshesPerFrame = config.getInt("maxMeshesPerFrame", "render", -1, -1, Integer.MAX_VALUE, ""); - sortFrequency = config.getInt("sortFrequency", "render", 1, 1, Integer.MAX_VALUE, ""); - gcRate = config.getInt("gcRate", "render", 1, 1, Integer.MAX_VALUE, "Maximum number of meshes to relocate each frame."); - VRAMSize = config.getInt("VRAMSize", "render", 1024, 1, Integer.MAX_VALUE, "VRAM buffer size (MB)."); - enableFog = config.getBoolean("enableFog", "render", true, ""); - debugPrefix = config.getInt("debugPrefix", "debug", Keyboard.KEY_F4, -1, Integer.MAX_VALUE, "This key has to be held down while pressing the debug keybinds. LWJGL keycode. Setting this to 0 will make the keybinds usable without holding anything else down. Setting this to -1 will disable debug keybinds entirely."); - debugInfoStartY = config.getInt("debugInfoStartY", "debug", 80, -1, Integer.MAX_VALUE, "The Y position of the first line of the debug info in the F3 overlay. Set this to -1 to disable showing that info."); - - if(config.hasChanged()) { - config.save(); - } + Config.configFile = event.getSuggestedConfigurationFile(); + Config.reloadConfig(); } @EventHandler @@ -131,8 +64,8 @@ public class Neodymium private void onPlayerWorldChanged(World newWorld) { if(getRendererWorld() == null && newWorld != null) { - reloadConfig(); - if(enabled) { + Config.reloadConfig(); + if(Config.enabled) { SpriteUtil.init(); } } @@ -140,7 +73,7 @@ public class Neodymium renderer.destroy(); renderer = null; } - if(enabled && newWorld != null) { + if(Config.enabled && newWorld != null) { renderer = new NeoRenderer(newWorld); } } @@ -211,7 +144,7 @@ public class Neodymium @SubscribeEvent public void onRenderOverlay(RenderGameOverlayEvent event) { FontRenderer fontRenderer = RenderManager.instance.getFontRenderer(); - if(isActive() && event.type == ElementType.TEXT && fontRenderer != null && Minecraft.getMinecraft().gameSettings.showDebugInfo && (Neodymium.debugInfoStartY != -1)) + if(isActive() && event.type == ElementType.TEXT && fontRenderer != null && Minecraft.getMinecraft().gameSettings.showDebugInfo && (Config.debugInfoStartY != -1)) { Minecraft mc = Minecraft.getMinecraft(); ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); @@ -220,7 +153,7 @@ public class Neodymium int yOffset = 0; for(String s : renderer.getDebugText()) { - fontRenderer.drawStringWithShadow(s, w - fontRenderer.getStringWidth(s) - 10, Neodymium.debugInfoStartY + yOffset, 0xFFFFFF); + fontRenderer.drawStringWithShadow(s, w - fontRenderer.getStringWidth(s) - 10, Config.debugInfoStartY + yOffset, 0xFFFFFF); yOffset += 10; } } diff --git a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java index 90b190d..86702fe 100644 --- a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java +++ b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java @@ -11,6 +11,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import makamys.neodymium.Config; import makamys.neodymium.Neodymium; import makamys.neodymium.ducks.IWorldRenderer; import makamys.neodymium.renderer.ChunkMesh; @@ -97,7 +98,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Inject(method = "postRenderBlocks", at = @At(value = "HEAD")) private void prePostRenderBlocks(int pass, EntityLivingBase entity, CallbackInfo ci) { - if(Neodymium.isActive() && !Neodymium.disableChunkMeshes) { + if(Neodymium.isActive() && !Config.disableChunkMeshes) { if(chunkMeshes != null) { chunkMeshes.add(ChunkMesh.fromTessellator(pass, WorldRenderer.class.cast(this), Tessellator.instance)); } diff --git a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java index baf906a..ee76b06 100644 --- a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java +++ b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java @@ -14,6 +14,7 @@ import java.util.stream.Collectors; import org.lwjgl.BufferUtils; +import makamys.neodymium.Config; import makamys.neodymium.MixinConfigPlugin; import makamys.neodymium.Neodymium; import makamys.neodymium.ducks.IWorldRenderer; @@ -84,7 +85,7 @@ public class ChunkMesh extends Mesh { int tessellatorYOffset = fr ? yOffset : 0; int tessellatorZOffset = fr ? zOffset : 0; - boolean optimize = Neodymium.optimizeChunkMeshes; + boolean optimize = Config.optimizeChunkMeshes; ChunkMesh.Flags flags = new ChunkMesh.Flags(t.hasTexture, t.hasBrightness, t.hasColor, t.hasNormals); diff --git a/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java b/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java index a57c4a5..81493cd 100644 --- a/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java +++ b/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import makamys.neodymium.Config; import makamys.neodymium.Neodymium; import makamys.neodymium.renderer.Mesh.GPUStatus; import makamys.neodymium.util.GuiHelper; @@ -30,7 +31,7 @@ public class GPUMemoryManager { public GPUMemoryManager() { VBO = glGenBuffers(); - bufferSize = Neodymium.VRAMSize * 1024 * 1024; + bufferSize = Config.VRAMSize * 1024 * 1024; glBindBuffer(GL_ARRAY_BUFFER, VBO); diff --git a/src/main/java/makamys/neodymium/renderer/NeoChunk.java b/src/main/java/makamys/neodymium/renderer/NeoChunk.java index 2a5651f..79deedf 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoChunk.java +++ b/src/main/java/makamys/neodymium/renderer/NeoChunk.java @@ -2,6 +2,7 @@ package makamys.neodymium.renderer; import java.util.List; +import makamys.neodymium.Config; import makamys.neodymium.Neodymium; import net.minecraft.entity.Entity; import net.minecraft.world.chunk.Chunk; @@ -101,7 +102,7 @@ public class NeoChunk { public void tick(Entity player) { double distSq = distSq(player); - if(Neodymium.disableSimpleMeshes || distSq < Math.pow((Neodymium.renderer.renderRange / 2) * 16, 2)) { + if(Config.disableSimpleMeshes || distSq < Math.pow((Neodymium.renderer.renderRange / 2) * 16, 2)) { setLOD(2); } else if(distSq < Math.pow((Neodymium.renderer.renderRange) * 16, 2)) { setLOD(1); @@ -164,7 +165,7 @@ public class NeoChunk { } public void receiveChunk(Chunk chunk) { - if(!Neodymium.disableSimpleMeshes) { + if(!Config.disableSimpleMeshes) { putSimpleMeshes(SimpleChunkMesh.generateSimpleMeshes(chunk)); } } diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index e721a62..f14c408 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -63,6 +63,7 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import org.lwjgl.util.vector.Matrix4f; +import makamys.neodymium.Config; import makamys.neodymium.Neodymium; import makamys.neodymium.ducks.IWorldRenderer; import makamys.neodymium.renderer.Mesh.GPUStatus; @@ -162,13 +163,13 @@ public class NeoRenderer { mem.runGC(false); } lastGCTime = System.currentTimeMillis(); - if(lastSaveTime == -1 || (System.currentTimeMillis() - lastSaveTime) > saveInterval && Neodymium.saveMeshes) { + if(lastSaveTime == -1 || (System.currentTimeMillis() - lastSaveTime) > saveInterval && Config.saveMeshes) { onSave(); lastSaveTime = System.currentTimeMillis(); } if(rendererActive && renderWorld) { - if(frameCount % Neodymium.sortFrequency == 0) { + if(frameCount % Config.sortFrequency == 0) { sort(); } @@ -215,7 +216,7 @@ public class NeoRenderer { piFirst[i].limit(sentMeshes[i].size()); piCount[i].limit(sentMeshes[i].size()); for(Mesh mesh : sentMeshes[i]) { - if(mesh.visible && (Neodymium.maxMeshesPerFrame == -1 || renderedMeshes < Neodymium.maxMeshesPerFrame)) { + if(mesh.visible && (Config.maxMeshesPerFrame == -1 || renderedMeshes < Config.maxMeshesPerFrame)) { renderedMeshes++; piFirst[i].put(mesh.iFirst); piCount[i].put(mesh.iCount); @@ -277,19 +278,19 @@ public class NeoRenderer { } public float getFarPlaneDistanceMultiplier() { - return (float)Neodymium.farPlaneDistanceMultiplier; + return (float)Config.farPlaneDistanceMultiplier; } public void afterSetupFog(int mode, float alpha, float farPlaneDistance) { EntityLivingBase entity = Minecraft.getMinecraft().renderViewEntity; if(Neodymium.fogEventWasPosted && !Minecraft.getMinecraft().theWorld.provider.doesXZShowFog((int)entity.posX, (int)entity.posZ)) { - GL11.glFogf(GL11.GL_FOG_START, mode < 0 ? 0 : farPlaneDistance * (float)Neodymium.fogStart); - GL11.glFogf(GL11.GL_FOG_END, mode < 0 ? farPlaneDistance/4 : farPlaneDistance * (float)Neodymium.fogEnd); + GL11.glFogf(GL11.GL_FOG_START, mode < 0 ? 0 : farPlaneDistance * (float)Config.fogStart); + GL11.glFogf(GL11.GL_FOG_END, mode < 0 ? farPlaneDistance/4 : farPlaneDistance * (float)Config.fogEnd); } } private void handleKeyboard() { - if(Neodymium.debugPrefix == 0 || (Neodymium.debugPrefix != -1 && Keyboard.isKeyDown(Neodymium.debugPrefix))) { + if(Config.debugPrefix == 0 || (Config.debugPrefix != -1 && Keyboard.isKeyDown(Config.debugPrefix))) { if(Keyboard.isKeyDown(Keyboard.KEY_F) && !wasDown[Keyboard.KEY_F]) { rendererActive = !rendererActive; } @@ -454,7 +455,7 @@ public class NeoRenderer { int fragmentShader; fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(fragmentShader, Util.readFile(Neodymium.enableFog ? "shaders/chunk_fog.frag" : "shaders/chunk.frag")); + glShaderSource(fragmentShader, Util.readFile(Config.enableFog ? "shaders/chunk_fog.frag" : "shaders/chunk.frag")); glCompileShader(fragmentShader); if(glGetShaderi(fragmentShader, GL_COMPILE_STATUS) == 0) { @@ -501,7 +502,7 @@ public class NeoRenderer { } public void onWorldRendererPost(WorldRenderer wr) { - if(Neodymium.disableChunkMeshes) return; + if(Config.disableChunkMeshes) return; int x = Math.floorDiv(wr.posX, 16); int y = Math.floorDiv(wr.posY, 16); @@ -536,7 +537,7 @@ public class NeoRenderer { } public synchronized void serverTick() { - int chunkLoadsRemaining = Neodymium.chunkLoadsPerTick; + int chunkLoadsRemaining = Config.chunkLoadsPerTick; while(!serverChunkLoadQueue.isEmpty() && chunkLoadsRemaining-- > 0) { ChunkCoordIntPair coords = serverChunkLoadQueue.remove(0); ChunkProviderServer chunkProviderServer = Minecraft.getMinecraft().getIntegratedServer().worldServerForDimension(world.provider.dimensionId).theChunkProviderServer; @@ -575,7 +576,7 @@ public class NeoRenderer { } public void lodChunkChanged(NeoChunk lodChunk) { - int newLOD = (!lodChunk.hasChunkMeshes() && lodChunk.lod == 2) ? (Neodymium.disableSimpleMeshes ? 0 : 1) : lodChunk.lod; + int newLOD = (!lodChunk.hasChunkMeshes() && lodChunk.lod == 2) ? (Config.disableSimpleMeshes ? 0 : 1) : lodChunk.lod; for(SimpleChunkMesh sm : lodChunk.simpleMeshes) { if(sm != null) { if(lodChunk.isFullyVisible() && newLOD == 1) { diff --git a/src/main/java/makamys/neodymium/renderer/SimpleChunkMesh.java b/src/main/java/makamys/neodymium/renderer/SimpleChunkMesh.java index d3d2501..0c21fe8 100644 --- a/src/main/java/makamys/neodymium/renderer/SimpleChunkMesh.java +++ b/src/main/java/makamys/neodymium/renderer/SimpleChunkMesh.java @@ -6,7 +6,7 @@ import java.util.List; import org.lwjgl.BufferUtils; -import makamys.neodymium.Neodymium; +import makamys.neodymium.Config; import makamys.neodymium.util.MCUtil; import net.minecraft.block.Block; import net.minecraft.block.BlockGrass; @@ -31,7 +31,7 @@ public class SimpleChunkMesh extends Mesh { } private static boolean isBad(Block block) { - for(Class clazz : Neodymium.blockClassBlacklist) { + for(Class clazz : Config.blockClassBlacklist) { if(clazz.isInstance(block)) { return true; } @@ -112,7 +112,7 @@ public class SimpleChunkMesh extends Mesh { } color = (0xFF << 24) | ((color >> 16 & 0xFF) << 0) | ((color >> 8 & 0xFF) << 8) | ((color >> 0 & 0xFF) << 16); - if((Neodymium.forceVanillaBiomeTemperature ? MCUtil.getBiomeTemperatureVanilla(biome, worldX, y, worldZ) + if((Config.forceVanillaBiomeTemperature ? MCUtil.getBiomeTemperatureVanilla(biome, worldX, y, worldZ) : biome.getFloatTemperature(worldX, y, worldZ)) < 0.15f) { builder.addCube(divX, divZ, worldY + 0.2f, 1f, Blocks.snow_layer.getIcon(1, 0), 0xFFFFFFFF, brightnessMult); |