Set up and implement a config menu
This commit is contained in:
@@ -10,6 +10,7 @@ import com.backsun.lod.objects.LodDimension;
|
||||
import com.backsun.lod.objects.LodRegion;
|
||||
import com.backsun.lod.objects.LodWorld;
|
||||
import com.backsun.lod.renderer.LodRenderer;
|
||||
import com.backsun.lod.util.LodConfig;
|
||||
import com.backsun.lod.util.LodFileHandler;
|
||||
import com.backsun.lodCore.util.RenderGlobalHook;
|
||||
|
||||
@@ -57,7 +58,8 @@ public class ClientProxy extends CommonProxy
|
||||
RenderGlobalHook.endRenderingStencil();
|
||||
GL11.glStencilFunc(GL11.GL_EQUAL, 0, 0xFF);
|
||||
|
||||
renderLods(event.getPartialTicks());
|
||||
if (LodConfig.drawLODs)
|
||||
renderLods(event.getPartialTicks());
|
||||
|
||||
GL11.glDisable(GL11.GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import com.backsun.lod.util.fog.FogDistance;
|
||||
import com.backsun.lod.util.enums.FogDistance;
|
||||
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
|
||||
@@ -17,11 +17,12 @@ import org.lwjgl.util.glu.Project;
|
||||
|
||||
import com.backsun.lod.objects.LodChunk;
|
||||
import com.backsun.lod.objects.LodDimension;
|
||||
import com.backsun.lod.util.LodConfig;
|
||||
import com.backsun.lod.util.ReflectionHandler;
|
||||
import com.backsun.lod.util.enums.ColorDirection;
|
||||
import com.backsun.lod.util.enums.FogDistance;
|
||||
import com.backsun.lod.util.enums.FogQuality;
|
||||
import com.backsun.lod.util.enums.LodLocation;
|
||||
import com.backsun.lod.util.fog.FogDistance;
|
||||
import com.backsun.lod.util.fog.FogQuality;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
@@ -39,6 +40,8 @@ import net.minecraft.util.math.Vec3i;
|
||||
*/
|
||||
public class LodRenderer
|
||||
{
|
||||
/** If true the LODs colors will be replaced with
|
||||
* a checkerboard, this can be used for debugging. */
|
||||
public boolean debugging = false;
|
||||
|
||||
private Minecraft mc;
|
||||
@@ -159,7 +162,18 @@ public class LodRenderer
|
||||
mc.mcProfiler.startSection("LOD setup");
|
||||
@SuppressWarnings("unused")
|
||||
long startTime = System.nanoTime();
|
||||
|
||||
if (LodConfig.drawCheckerBoard)
|
||||
{
|
||||
if (debugging != LodConfig.drawCheckerBoard)
|
||||
regen = true;
|
||||
debugging = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (debugging != LodConfig.drawCheckerBoard)
|
||||
regen = true;
|
||||
debugging = false;
|
||||
}
|
||||
|
||||
|
||||
// color setup
|
||||
@@ -321,6 +335,8 @@ public class LodRenderer
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// rendering //
|
||||
//===========//
|
||||
@@ -329,13 +345,32 @@ public class LodRenderer
|
||||
if (regen)
|
||||
generateLodBuffers(lodArray, colorArray, FogDistance.BOTH, new Vec3i(startX, 0, startZ));
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
setupFog(FogDistance.NEAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(nearBuffers);
|
||||
switch(LodConfig.fogDistance)
|
||||
{
|
||||
case BOTH:
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
setupFog(FogDistance.NEAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(nearBuffers);
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
setupFog(FogDistance.FAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(farBuffers);
|
||||
break;
|
||||
case NEAR:
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
setupFog(FogDistance.NEAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(nearBuffers);
|
||||
sendLodsToGpuAndDraw(farBuffers);
|
||||
break;
|
||||
case FAR:
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
setupFog(FogDistance.FAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(nearBuffers);
|
||||
sendLodsToGpuAndDraw(farBuffers);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
setupFog(FogDistance.FAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(farBuffers);
|
||||
|
||||
|
||||
|
||||
@@ -498,8 +533,6 @@ public class LodRenderer
|
||||
// the multipliers are percentages
|
||||
// of the regular view distance.
|
||||
|
||||
// TODO add the ability to change the fogDistanceMode
|
||||
// in the mod settings
|
||||
if(fogDistance == FogDistance.NEAR)
|
||||
{
|
||||
// the reason that I wrote fogEnd then fogStart backwards
|
||||
@@ -507,7 +540,7 @@ public class LodRenderer
|
||||
// it is normally used, with it hiding near objects
|
||||
// instead of far objects.
|
||||
|
||||
if (fogQuality == FogQuality.FANCY || fogQuality == FogQuality.UNKNOWN)
|
||||
if (fogQuality == FogQuality.FANCY)
|
||||
{
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 0.3f * (VIEW_DISTANCE_MULTIPLIER * 0.5f));
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.35f * (VIEW_DISTANCE_MULTIPLIER * 0.5f));
|
||||
@@ -524,7 +557,7 @@ public class LodRenderer
|
||||
}
|
||||
else if(fogDistance == FogDistance.FAR)
|
||||
{
|
||||
if (fogQuality == FogQuality.FANCY || fogQuality == FogQuality.UNKNOWN)
|
||||
if (fogQuality == FogQuality.FANCY)
|
||||
{
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.78f * (VIEW_DISTANCE_MULTIPLIER * 0.5f)); // TODO rename to view_distance_radius
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 1.0f * (VIEW_DISTANCE_MULTIPLIER * 0.5f));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.backsun.lod.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.backsun.lod.util.enums.FogDistance;
|
||||
import com.backsun.lod.util.enums.FogQuality;
|
||||
|
||||
import net.minecraftforge.common.config.Config;
|
||||
import net.minecraftforge.common.config.ConfigManager;
|
||||
@@ -12,10 +12,62 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
/**
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 09-19-2020
|
||||
* @version 02-14-2021
|
||||
*/
|
||||
@Config(modid = Reference.MOD_ID)
|
||||
public class LodConfig
|
||||
{
|
||||
// save the config file when it is changed
|
||||
@Mod.EventBusSubscriber(modid = Reference.MOD_ID)
|
||||
private static class EventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent event)
|
||||
{
|
||||
if (event.getModID().equals(Reference.MOD_ID))
|
||||
{
|
||||
ConfigManager.sync(Reference.MOD_ID, Config.Type.INSTANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Config.Comment(
|
||||
{"Enable LODs",
|
||||
"If true LODs will be drawn, if false LODs will "
|
||||
+ "still be generated and stored in your world's save folder, "
|
||||
+ "but they won't be rendered."})
|
||||
public static boolean drawLODs = true;
|
||||
|
||||
@Config.Comment(
|
||||
{"Fog Distance",
|
||||
"What distance should Fog be drawn on the LODs?"})
|
||||
public static FogDistance fogDistance = FogDistance.BOTH;
|
||||
|
||||
@Config.Comment(
|
||||
{"Use Optifine Fog Quality Setting",
|
||||
"Should the LODs use Optifine's fog quality (Fast or Fancy) setting?"})
|
||||
public static boolean useOptifineFogQuality = true;
|
||||
|
||||
@Config.Comment(
|
||||
{"Fog Quality Override",
|
||||
"This is only used if \"Use Optifine FogQuality\" "
|
||||
+ "is set to false, or if Optifine can't be found."})
|
||||
public static FogQuality fogQualityOverride = FogQuality.FANCY;
|
||||
|
||||
@Config.Comment(
|
||||
{"Draw Debugging Checkerboard",
|
||||
"If false the LODs will draw with their normal world colors."
|
||||
+ "If true they will draw as a black and white checkerboard."
|
||||
+ "This can be used for debugging or imagining you are playing a "
|
||||
+ "giant game of chess ;)"})
|
||||
public static boolean drawCheckerBoard = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
class ExampleConfig
|
||||
{
|
||||
@Config.Comment("This is an example boolean property.")
|
||||
public static boolean fooBar = false;
|
||||
@@ -75,11 +127,10 @@ public class LodConfig
|
||||
private static class EventHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* Inject the new values and save
|
||||
* to the config file when the
|
||||
* config has been changed from the GUI.
|
||||
*/
|
||||
|
||||
// Inject the new values and save
|
||||
// to the config file when the
|
||||
// config has been changed from the GUI.
|
||||
@SubscribeEvent
|
||||
public static void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent event) {
|
||||
if (event.getModID().equals(Reference.MOD_ID))
|
||||
@@ -89,6 +140,5 @@ public class LodConfig
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
|
||||
import com.backsun.lod.util.fog.FogQuality;
|
||||
import com.backsun.lod.util.enums.FogQuality;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@@ -131,12 +131,13 @@ public class ReflectionHandler
|
||||
*/
|
||||
public FogQuality getFogQuality()
|
||||
{
|
||||
if (ofFogField == null)
|
||||
if (!LodConfig.useOptifineFogQuality || ofFogField == null)
|
||||
{
|
||||
// either optifine isn't installed,
|
||||
// the variable name was changed,
|
||||
// or the setup method wasn't called yet.
|
||||
return FogQuality.UNKNOWN;
|
||||
// the setup method wasn't called yet, or
|
||||
// the user wants to use their own quality setting.
|
||||
return LodConfig.fogQualityOverride;
|
||||
}
|
||||
|
||||
int returnNum = 0;
|
||||
@@ -147,13 +148,13 @@ public class ReflectionHandler
|
||||
}
|
||||
catch (IllegalArgumentException | IllegalAccessException e)
|
||||
{
|
||||
System.out.println(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
switch (returnNum)
|
||||
{
|
||||
case 0:
|
||||
return FogQuality.UNKNOWN;
|
||||
return FogQuality.FAST;
|
||||
case 1:
|
||||
return FogQuality.FAST;
|
||||
case 2:
|
||||
@@ -162,7 +163,7 @@ public class ReflectionHandler
|
||||
return FogQuality.OFF;
|
||||
|
||||
default:
|
||||
return FogQuality.UNKNOWN;
|
||||
return FogQuality.FAST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,8 +179,7 @@ public class ReflectionHandler
|
||||
}
|
||||
catch(InvocationTargetException | IllegalAccessException | IllegalArgumentException e)
|
||||
{
|
||||
// hopefully this should never be called
|
||||
System.out.println(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.backsun.lod.util.fog;
|
||||
package com.backsun.lod.util.enums;
|
||||
|
||||
/**
|
||||
* Near, far, or both.
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.backsun.lod.util.fog;
|
||||
package com.backsun.lod.util.enums;
|
||||
|
||||
/**
|
||||
* Unknown, fast, fancy, or off
|
||||
* fast, fancy, or off
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 01-27-2021
|
||||
* @version 02-14-2021
|
||||
*/
|
||||
public enum FogQuality
|
||||
{
|
||||
UNKNOWN,
|
||||
FAST,
|
||||
FANCY,
|
||||
OFF;
|
||||
|
||||
Reference in New Issue
Block a user