Pregen test

This commit is contained in:
Leonardo
2021-11-03 19:25:27 +01:00
parent c5a2944d68
commit d8091ab62a
6 changed files with 65 additions and 31 deletions
@@ -33,6 +33,7 @@ import com.seibel.lod.builders.lodBuilding.LodBuilder;
import com.seibel.lod.builders.lodBuilding.LodBuilderConfig;
import com.seibel.lod.config.LodConfig;
import com.seibel.lod.enums.DistanceGenerationMode;
import com.seibel.lod.handlers.ChunkLoader;
import com.seibel.lod.objects.LodDimension;
import com.seibel.lod.proxy.ClientProxy;
import com.seibel.lod.util.LodUtil;
@@ -190,9 +191,8 @@ public class LodGenWorker implements IWorker
//}
//else
//{
/*
IChunk loadedChunk = null;
if (lodDim.isChunkPreGenerated(pos.x, pos.z) && LodConfig.CLIENT.worldGenerator.useExperimentalPreGenLoading.get())
if (lodDim.isChunkPreGenerated(pos.x, pos.z) && ClientProxy.pregen)
{
// generate a Lod like normal
loadedChunk = ChunkLoader.getChunkFromFile(pos);
@@ -227,7 +227,7 @@ public class LodGenWorker implements IWorker
}
}
else
{*/
{
switch (generationMode)
{
case NONE:
@@ -251,7 +251,7 @@ public class LodGenWorker implements IWorker
generateWithServer();
break;
}
//}
}
//lodRenderer.regenerateLODsNextFrame();
@@ -135,7 +135,7 @@ public class LodWorldGenerator
// an easy way to do so.
// add the near positions
if (posToGenerate.getNthDetail(nearIndex, true) != 0 && nearIndex < posToGenerate.getNumberOfNearPos())
if (nearIndex < posToGenerate.getNumberOfNearPos() && posToGenerate.getNthDetail(nearIndex, true) != 0)
{
detailLevel = (byte) (posToGenerate.getNthDetail(nearIndex, true) - 1);
posX = posToGenerate.getNthPosX(nearIndex, true);
@@ -160,7 +160,7 @@ public class LodWorldGenerator
// add the far positions
if (posToGenerate.getNthDetail(farIndex, false) != 0 && farIndex < posToGenerate.getNumberOfFarPos())
if (farIndex < posToGenerate.getNumberOfFarPos() && posToGenerate.getNthDetail(farIndex, false) != 0)
{
detailLevel = (byte) (posToGenerate.getNthDetail(farIndex, false) - 1);
posX = posToGenerate.getNthPosX(farIndex, false);
@@ -480,12 +480,18 @@ public class LodConfig
{
public final ForgeConfigSpec.BooleanValue drawLods;
public final ForgeConfigSpec.EnumValue<DebugMode> debugMode;
public final ForgeConfigSpec.BooleanValue usePregen;
public final ForgeConfigSpec.BooleanValue enableDebugKeybindings;
Debugging(ForgeConfigSpec.Builder builder)
{
builder.comment("These settings can be used to look for bugs, or see how certain aspects of the mod work.").push(this.getClass().getSimpleName());
usePregen = builder
.comment("\n\n"
+ " if true the game will use pregen when possible \n")
.define("Use Pregen", false);
drawLods = builder
.comment("\n\n"
+ " If true, the mod is enabled and fake chunks will be drawn. \n"
@@ -29,6 +29,7 @@ import com.seibel.lod.enums.DistanceGenerationMode;
import com.seibel.lod.enums.GenerationPriority;
import com.seibel.lod.enums.VerticalQuality;
import com.seibel.lod.handlers.LodDimensionFileHandler;
import com.seibel.lod.proxy.ClientProxy;
import com.seibel.lod.util.DataPointUtil;
import com.seibel.lod.util.DetailDistanceUtil;
import com.seibel.lod.util.LevelPosUtil;
@@ -602,6 +603,9 @@ public class LodDimension
//if(lodRegion.isChunkPreGenerated(xChunkToCheck,zChunkToCheck))
// complexity = DistanceGenerationMode.SERVER.complexity;
//else
if(ClientProxy.pregen)
complexity = DistanceGenerationMode.SERVER.complexity;
else
complexity = LodConfig.CLIENT.worldGenerator.distanceGenerationMode.get().complexity;
@@ -817,15 +821,15 @@ public class LodDimension
/**
* Return true if the chunk has been pregenerated in game
*/
//public boolean isChunkPreGenerated(int xChunkPos, int zChunkPos)
//{
//
// LodRegion region = getRegion(LodUtil.CHUNK_DETAIL_LEVEL, xChunkPos, zChunkPos);
// if (region == null)
// return false;
//
// return region.isChunkPreGenerated(xChunkPos, zChunkPos);
//}
public boolean isChunkPreGenerated(int xChunkPos, int zChunkPos)
{
LodRegion region = getRegion(LodUtil.CHUNK_DETAIL_LEVEL, xChunkPos, zChunkPos);
if (region == null)
return false;
return region.isChunkPreGenerated(xChunkPos, zChunkPos);
}
/**
* Returns whether the region at the given RegionPos
@@ -25,6 +25,13 @@ import com.seibel.lod.util.DataPointUtil;
import com.seibel.lod.util.DetailDistanceUtil;
import com.seibel.lod.util.LevelPosUtil;
import com.seibel.lod.util.LodUtil;
import com.seibel.lod.wrappers.MinecraftWrapper;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.storage.RegionFile;
import net.minecraft.world.server.ServerChunkProvider;
import net.minecraft.world.server.ServerWorld;
import java.io.File;
/**
* This object holds all loaded LevelContainers acting as a quad tree
@@ -58,7 +65,7 @@ public class LodRegion
/**
* This chunk Pos has been generated
*/
//private final boolean[] preGeneratedChunkPos;
private final boolean[] preGeneratedChunkPos;
/**
* the generation mode for this region
@@ -96,9 +103,9 @@ public class LodRegion
boolean fileFound = false;
/*
preGeneratedChunkPos = new boolean[32 * 32];
if (MinecraftWrapper.INSTANCE.hasSinglePlayerServer() && LodConfig.CLIENT.worldGenerator.useExperimentalPreGenLoading.get())
if (MinecraftWrapper.INSTANCE.hasSinglePlayerServer())
{
File regionFileDirHead;
File regionFileDirParent;
@@ -108,7 +115,7 @@ public class LodRegion
// provider needs a separate variable to prevent
// the compiler from complaining
StringBuilder string = new StringBuilder();
//StringBuilder string = new StringBuilder();
try
{
ServerChunkProvider provider = serverWorld.getChunkSource();
@@ -119,7 +126,7 @@ public class LodRegion
{
regionFileDirParent = regionFileDirHead.getParentFile();
//string.append(regionFileDirParent.toString());
string.append(regionFileDirHead);
//string.append(regionFileDirHead);
RegionFile regionFile = new RegionFile(regionFileDirHead, regionFileDirParent, true);
for (int x = 0; x < 32; x++)
{
@@ -129,7 +136,7 @@ public class LodRegion
}
}
string.append("region " + regionPosX + " " + regionPosZ + "\n");
/*string.append("region " + regionPosX + " " + regionPosZ + "\n");
for (int x = 0; x < 32; x++)
{
for (int z = 0; z < 32; z++)
@@ -137,8 +144,8 @@ public class LodRegion
//regionFile.doesChunkExist()
string.append(preGeneratedChunkPos[x * 32 + z] + "\t");
}
string.append("\n");
}
//string.append("\n");
}*/
regionFile.close();
}
}
@@ -146,8 +153,8 @@ public class LodRegion
{
e.printStackTrace();
}
System.out.println(string);
}*/
//System.out.println(string);
}
}
@@ -155,12 +162,12 @@ public class LodRegion
/**
* Return true if the chunk has been pregenerated in game
*/
//public boolean isChunkPreGenerated(int xChunkPos, int zChunkPos)
//{
// xChunkPos = LevelPosUtil.getRegionModule(LodUtil.CHUNK_DETAIL_LEVEL, xChunkPos);
// zChunkPos = LevelPosUtil.getRegionModule(LodUtil.CHUNK_DETAIL_LEVEL, zChunkPos);
// return preGeneratedChunkPos[xChunkPos * 32 + zChunkPos];
//}
public boolean isChunkPreGenerated(int xChunkPos, int zChunkPos)
{
xChunkPos = LevelPosUtil.getRegionModule(LodUtil.CHUNK_DETAIL_LEVEL, xChunkPos);
zChunkPos = LevelPosUtil.getRegionModule(LodUtil.CHUNK_DETAIL_LEVEL, zChunkPos);
return preGeneratedChunkPos[xChunkPos * 32 + zChunkPos];
}
/**
* Inserts the data point into the region.
@@ -19,6 +19,8 @@
package com.seibel.lod.proxy;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.util.text.TextComponent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;
@@ -65,6 +67,8 @@ public class ClientProxy
*/
private boolean firstTimeSetupComplete = false;
public static boolean pregen = false;
private static final LodWorld lodWorld = new LodWorld();
private static final LodBuilder lodBuilder = new LodBuilder();
private static final LodBufferBuilder lodBufferBuilder = new LodBufferBuilder();
@@ -225,6 +229,7 @@ public class ClientProxy
@SubscribeEvent
public void worldLoadEvent(WorldEvent.Load event)
{
pregen = false;
DataPointUtil.worldHeight = event.getWorld().getHeight();
//LodNodeGenWorker.restartExecutorService();
//ThreadMapUtil.clearMaps();
@@ -240,6 +245,7 @@ public class ClientProxy
@SubscribeEvent
public void worldUnloadEvent(WorldEvent.Unload event)
{
pregen = false;
// the player just unloaded a world/dimension
ThreadMapUtil.clearMaps();
@@ -299,6 +305,17 @@ public class ClientProxy
{
LodConfig.CLIENT.advancedModOptions.debugging.drawLods.set(!LodConfig.CLIENT.advancedModOptions.debugging.drawLods.get());
}
if (LodConfig.CLIENT.advancedModOptions.debugging.enableDebugKeybindings.get()
&& event.getKey() == GLFW.GLFW_KEY_F7 && event.getAction() == GLFW.GLFW_PRESS)
{
pregen = !pregen;
ClientPlayerEntity player = MinecraftWrapper.INSTANCE.getPlayer();
if(pregen)
player.sendMessage(new StringTextComponent("pregen activated."),player.getUUID());
else
player.sendMessage(new StringTextComponent("pregen de-activated."),player.getUUID());
}
}