add config assumePreExistingChunksAreFinished

This commit is contained in:
James Seibel
2024-12-20 15:27:03 -06:00
parent 9accb6d584
commit 70d897f09c
10 changed files with 53 additions and 53 deletions
@@ -22,7 +22,6 @@ package com.seibel.distanthorizons.common.wrappers.chunk;
import com.seibel.distanthorizons.common.wrappers.block.BiomeWrapper;
import com.seibel.distanthorizons.common.wrappers.block.BlockStateWrapper;
import com.seibel.distanthorizons.common.wrappers.misc.MutableBlockPosWrapper;
import com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject.DhLitWorldGenRegion;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
@@ -36,8 +35,8 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.levelgen.Heightmap;
import org.apache.logging.log4j.Logger;
@@ -122,7 +121,7 @@ public class ChunkWrapper implements IChunkWrapper
this.solidHeightMap = new int[LodUtil.CHUNK_WIDTH][LodUtil.CHUNK_WIDTH];
this.lightBlockingHeightMap = new int[LodUtil.CHUNK_WIDTH][LodUtil.CHUNK_WIDTH];
this.recalculateDhHeightMaps();
this.recalculateDhHeightMapsIfNeeded();
}
else
{
@@ -250,8 +249,8 @@ public class ChunkWrapper implements IChunkWrapper
}
private int getChunkSectionMinHeight(int index) { return (index * 16) + this.getInclusiveMinBuildHeight(); }
public void recalculateDhHeightMaps()
/** Will only run if the config says the MC heightmaps shouldn't be trusted. */
public void recalculateDhHeightMapsIfNeeded()
{
// re-calculate the min/max heights for consistency (during world gen these may be wrong)
this.minNonEmptyHeight = Integer.MIN_VALUE;
@@ -394,6 +393,20 @@ public class ChunkWrapper implements IChunkWrapper
public ChunkAccess getChunk() { return this.chunk; }
public void trySetStatus(ChunkStatus status) { trySetStatus(this.getChunk(), status); }
/** does nothing if the chunk object doesn't support setting it's status */
public static void trySetStatus(ChunkAccess chunk, ChunkStatus status)
{
if (chunk instanceof ProtoChunk)
{
#if MC_VER < MC_1_21_1
((ProtoChunk) chunk).setStatus(STATUS);
#else
((ProtoChunk) chunk).setPersistedStatus(status);
#endif
}
}
public ChunkStatus getStatus() { return getStatus(this.getChunk()); }
public static ChunkStatus getStatus(ChunkAccess chunk)
{
@@ -378,7 +378,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
// We handle this later, although that handling would need to change if the gen size ever changes.
LodUtil.assertTrue(genEvent.size % 2 == 0, "Generation events are expected to be an evan number of chunks wide.");
if (genEvent.targetGenerationStep == EDhApiWorldGenerationStep.LIGHT) // TODO using something other than LIGHT would be good for clarity
if (genEvent.generatorMode == EDhApiDistantGeneratorMode.INTERNAL_SERVER)
{
return this.generateChunksViaInternalServerAsync(genEvent);
}
@@ -515,7 +515,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
try
{
this.generateDirect(genEvent, chunkWrapperList, borderSize, genEvent.targetGenerationStep, region);
this.generateDirect(genEvent, chunkWrapperList, region);
}
catch (InterruptedException e)
{
@@ -669,7 +669,17 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
@Nullable
ChunkAccess chunk = ChunkLoader.read(level, chunkPos, chunkData);
if (chunk == null)
if (chunk != null)
{
if (Config.Common.LodBuilding.assumePreExistingChunksAreFinished.get())
{
// Sometimes the chunk status is wrong
// (this might be an issue with some versions of chunky)
// which can cause issues with some world gen steps re-running and locking up
ChunkWrapper.trySetStatus(chunk, ChunkStatus.FULL);
}
}
else
{
chunk = CreateEmptyChunk(level, chunkPos);
}
@@ -761,7 +771,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
ArrayList<IChunkWrapper> chunksToLight = new ArrayList<>(chunkWrappersByDhPos.values());
for (IChunkWrapper iChunkWrapper : chunksToLight)
{
((ChunkWrapper) iChunkWrapper).recalculateDhHeightMaps();
((ChunkWrapper) iChunkWrapper).recalculateDhHeightMapsIfNeeded();
// pre-generated chunks should have lighting but new ones won't
if (!iChunkWrapper.isDhBlockLightingCorrect())
@@ -898,8 +908,8 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
}
public void generateDirect(
GenerationEvent genEvent, ArrayGridList<ChunkWrapper> chunkWrappersToGenerate, int border,
EDhApiWorldGenerationStep step, DhLitWorldGenRegion region) throws InterruptedException
GenerationEvent genEvent, ArrayGridList<ChunkWrapper> chunkWrappersToGenerate,
DhLitWorldGenRegion region) throws InterruptedException
{
if (Thread.interrupted())
{
@@ -919,8 +929,10 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
}
});
EDhApiWorldGenerationStep step = genEvent.targetGenerationStep;
if (step == EDhApiWorldGenerationStep.EMPTY)
{
// shouldn't normally happen but is here for consistency with the other world gen steps
return;
}
@@ -1016,7 +1028,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
// make sure the height maps are all properly generated
// if this isn't done everything else afterward may fail
Heightmap.primeHeightmaps(centerChunk.getChunk(), ChunkStatus.FEATURES.heightmapsAfter());
centerChunk.recalculateDhHeightMaps();
centerChunk.recalculateDhHeightMapsIfNeeded();
// pre-generated chunks should have lighting but new ones won't
if (!centerChunk.isDhBlockLightingCorrect())
@@ -1069,13 +1081,14 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
@Override
public CompletableFuture<Void> generateChunks(
int minX, int minZ, int genSize, EDhApiWorldGenerationStep targetStep,
int minX, int minZ, int genSize,
EDhApiDistantGeneratorMode generatorMode, EDhApiWorldGenerationStep targetStep,
ExecutorService worldGeneratorThreadPool, Consumer<IChunkWrapper> resultConsumer)
{
//System.out.println("GenerationEvent: "+genSize+"@"+minX+","+minZ+" "+targetStep);
// TODO: Check event overlap via e.tooClose()
GenerationEvent genEvent = GenerationEvent.startEvent(new DhChunkPos(minX, minZ), genSize, this, targetStep, resultConsumer, worldGeneratorThreadPool);
GenerationEvent genEvent = GenerationEvent.startEvent(new DhChunkPos(minX, minZ), genSize, this, generatorMode, targetStep, resultConsumer, worldGeneratorThreadPool);
this.generationEventList.add(genEvent);
return genEvent.future;
}
@@ -23,6 +23,7 @@ import java.lang.invoke.MethodHandles;
import java.util.concurrent.*;
import java.util.function.Consumer;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.distanthorizons.core.util.objects.UncheckedInterruptedException;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
@@ -44,6 +45,7 @@ public final class GenerationEvent
/** the number of chunks wide this event is */
public final int size;
public final EDhApiWorldGenerationStep targetGenerationStep;
public final EDhApiDistantGeneratorMode generatorMode;
public EventTimer timer = null;
public long inQueueTime;
public long timeoutTime = -1;
@@ -54,12 +56,13 @@ public final class GenerationEvent
public GenerationEvent(
DhChunkPos minPos, int size, BatchGenerationEnvironment generationGroup,
EDhApiWorldGenerationStep targetGenerationStep, Consumer<IChunkWrapper> resultConsumer)
EDhApiDistantGeneratorMode generatorMode, EDhApiWorldGenerationStep targetGenerationStep, Consumer<IChunkWrapper> resultConsumer)
{
this.inQueueTime = System.nanoTime();
this.id = generationFutureDebugIDs++;
this.minPos = minPos;
this.size = size;
this.generatorMode = generatorMode;
this.targetGenerationStep = targetGenerationStep;
this.threadedParam = ThreadedParameters.getOrMake(generationGroup.params);
this.resultConsumer = resultConsumer;
@@ -69,10 +72,10 @@ public final class GenerationEvent
public static GenerationEvent startEvent(
DhChunkPos minPos, int size, BatchGenerationEnvironment genEnvironment,
EDhApiWorldGenerationStep target, Consumer<IChunkWrapper> resultConsumer,
EDhApiDistantGeneratorMode generatorMode, EDhApiWorldGenerationStep target, Consumer<IChunkWrapper> resultConsumer,
ExecutorService worldGeneratorThreadPool)
{
GenerationEvent generationEvent = new GenerationEvent(minPos, size, genEnvironment, target, resultConsumer);
GenerationEvent generationEvent = new GenerationEvent(minPos, size, genEnvironment, generatorMode, target, resultConsumer);
generationEvent.future = CompletableFuture.supplyAsync(() ->
{
long runStartTime = System.nanoTime();
@@ -68,12 +68,7 @@ public final class StepBiomes
}
else if (chunk instanceof ProtoChunk)
{
#if MC_VER < MC_1_21_1
((ProtoChunk) chunk).setStatus(STATUS);
#else
((ProtoChunk) chunk).setPersistedStatus(STATUS);
#endif
chunkWrapper.trySetStatus(STATUS);
chunksToDo.add(chunk);
}
}
@@ -66,11 +66,7 @@ public final class StepFeatures
}
else if (chunk instanceof ProtoChunk)
{
#if MC_VER < MC_1_21_1
((ProtoChunk) chunk).setStatus(STATUS);
#else
((ProtoChunk) chunk).setPersistedStatus(STATUS);
#endif
chunkWrapper.trySetStatus(STATUS);
}
@@ -67,12 +67,7 @@ public final class StepNoise
{
continue;
}
#if MC_VER < MC_1_21_1
((ProtoChunk) chunk).setStatus(STATUS);
#else
((ProtoChunk) chunk).setPersistedStatus(STATUS);
#endif
chunkWrapper.trySetStatus(STATUS);
chunksToDo.add(chunk);
}
@@ -66,12 +66,7 @@ public final class StepStructureReference
}
else if (chunk instanceof ProtoChunk)
{
#if MC_VER < MC_1_21_1
((ProtoChunk) chunk).setStatus(STATUS);
#else
((ProtoChunk) chunk).setPersistedStatus(STATUS);
#endif
chunksToDo.add(chunk);
chunkWrapper.trySetStatus(STATUS);
}
}
@@ -85,12 +85,7 @@ public final class StepStructureStart
}
else if (chunk instanceof ProtoChunk)
{
#if MC_VER < MC_1_21_1
((ProtoChunk) chunk).setStatus(STATUS);
#else
((ProtoChunk) chunk).setPersistedStatus(STATUS);
#endif
chunksToDo.add(chunk);
chunkWrapper.trySetStatus(STATUS);
}
}
@@ -65,12 +65,7 @@ public final class StepSurface
}
else if (chunk instanceof ProtoChunk)
{
#if MC_VER < MC_1_21_1
((ProtoChunk) chunk).setStatus(STATUS);
#else
((ProtoChunk) chunk).setPersistedStatus(STATUS);
#endif
chunkWrapper.trySetStatus(STATUS);
chunksToDo.add(chunk);
}
}