diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index 52353eefb..166c2d769 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -418,7 +418,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm .findFirst() .orElseGet(() -> regionChunks.getFirst()); - genEvent.refreshTimeout(); DhLitWorldGenRegion region = new DhLitWorldGenRegion( centerX, centerZ, centerChunk, @@ -504,8 +503,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm ChunkWrapper wrappedChunk = chunkWrappersByDhPos.get(dhPos); genEvent.resultConsumer.accept(wrappedChunk); } - - genEvent.refreshTimeout(); } catch (CompletionException | UncheckedInterruptedException e) { @@ -533,6 +530,11 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm // new ChunkPos(genMinX + (width - 1) + extraRadius, genMinZ + (width - 1) + extraRadius) //); } + + + + // get existing chunk // + /** * If the given chunk pos already exists in the world, that chunk will be returned, * otherwise this will return an empty chunk. @@ -750,6 +752,8 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm + // internal server generation // + private CompletableFuture generateChunksViaInternalServerAsync(GenerationEvent genEvent) throws InterruptedException { LinkedBlockingQueue runnableQueue = new LinkedBlockingQueue<>(); @@ -829,8 +833,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm ChunkPos chunkPos = iterator.next(); releaseChunkToServer(this.params.level, chunkPos, true); } - - genEvent.refreshTimeout(); }); processGeneratedChunksFuture.whenCompleteAsync((unused, throwable) -> { }, runnableQueue::add); // trigger wakeup @@ -941,6 +943,10 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm }); } + + + // direct generation // + public void generateDirect( GenerationEvent genEvent, ArrayGridList chunkWrappersToGenerate, DhLitWorldGenRegion region) throws InterruptedException @@ -972,7 +978,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm throwIfThreadInterrupted(); this.stepStructureStart.generateGroup(genEvent.threadedParam, region, GetCutoutFrom(chunkWrappersToGenerate, EDhApiWorldGenerationStep.STRUCTURE_START)); - genEvent.refreshTimeout(); if (step == EDhApiWorldGenerationStep.STRUCTURE_START) { return; @@ -980,7 +985,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm throwIfThreadInterrupted(); this.stepStructureReference.generateGroup(genEvent.threadedParam, region, GetCutoutFrom(chunkWrappersToGenerate, EDhApiWorldGenerationStep.STRUCTURE_REFERENCE)); - genEvent.refreshTimeout(); if (step == EDhApiWorldGenerationStep.STRUCTURE_REFERENCE) { return; @@ -988,7 +992,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm throwIfThreadInterrupted(); this.stepBiomes.generateGroup(genEvent.threadedParam, region, GetCutoutFrom(chunkWrappersToGenerate, EDhApiWorldGenerationStep.BIOMES)); - genEvent.refreshTimeout(); if (step == EDhApiWorldGenerationStep.BIOMES) { return; @@ -996,7 +999,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm throwIfThreadInterrupted(); this.stepNoise.generateGroup(genEvent.threadedParam, region, GetCutoutFrom(chunkWrappersToGenerate, EDhApiWorldGenerationStep.NOISE)); - genEvent.refreshTimeout(); if (step == EDhApiWorldGenerationStep.NOISE) { return; @@ -1004,7 +1006,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm throwIfThreadInterrupted(); this.stepSurface.generateGroup(genEvent.threadedParam, region, GetCutoutFrom(chunkWrappersToGenerate, EDhApiWorldGenerationStep.SURFACE)); - genEvent.refreshTimeout(); if (step == EDhApiWorldGenerationStep.SURFACE) { return; @@ -1019,7 +1020,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm throwIfThreadInterrupted(); this.stepFeatures.generateGroup(genEvent.threadedParam, region, GetCutoutFrom(chunkWrappersToGenerate, EDhApiWorldGenerationStep.FEATURES)); - genEvent.refreshTimeout(); } finally { @@ -1063,8 +1063,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm this.serverLevel.updateBeaconBeamsForChunk(centerChunk, iChunkWrapperList); } - - genEvent.refreshTimeout(); } } private static ArrayGridList GetCutoutFrom(ArrayGridList total, int border) { return new ArrayGridList<>(total, border, total.gridSize - border); } @@ -1074,14 +1072,14 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm @Override public CompletableFuture generateChunks( - int minX, int minZ, int genSize, + int minX, int minZ, int chunkWidthCount, EDhApiDistantGeneratorMode generatorMode, EDhApiWorldGenerationStep targetStep, ExecutorService worldGeneratorThreadPool, Consumer 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, generatorMode, targetStep, resultConsumer, worldGeneratorThreadPool); + GenerationEvent genEvent = GenerationEvent.startEvent( + new DhChunkPos(minX, minZ), chunkWidthCount, this, + generatorMode, targetStep, resultConsumer, + worldGeneratorThreadPool); this.generationEventList.add(genEvent); return genEvent.future; } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GenerationEvent.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GenerationEvent.java index 3d6ec4c0d..313ae3ca9 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GenerationEvent.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GenerationEvent.java @@ -25,11 +25,8 @@ 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.ExceptionUtil; -import com.seibel.distanthorizons.core.util.PerfRecorder; -import com.seibel.distanthorizons.core.util.objects.UncheckedInterruptedException; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.pos.DhChunkPos; -import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper; import com.seibel.distanthorizons.core.logging.DhLogger; @@ -48,8 +45,6 @@ public final class GenerationEvent public final int widthInChunks; public final EDhApiWorldGenerationStep targetGenerationStep; public final EDhApiDistantGeneratorMode generatorMode; - public long inQueueTime; - public long timeoutTime = -1; public final CompletableFuture future = new CompletableFuture<>(); public final Consumer resultConsumer; @@ -59,11 +54,10 @@ public final class GenerationEvent // constructor // //=============// - public GenerationEvent( + private GenerationEvent( DhChunkPos minPos, int widthInChunks, BatchGenerationEnvironment generationGroup, EDhApiDistantGeneratorMode generatorMode, EDhApiWorldGenerationStep targetGenerationStep, Consumer resultConsumer) { - this.inQueueTime = System.nanoTime(); this.id = generationFutureDebugIDs++; this.minPos = minPos; this.widthInChunks = widthInChunks; @@ -75,12 +69,16 @@ public final class GenerationEvent + //=======// + // start // + //=======// + public static GenerationEvent startEvent( - DhChunkPos minPos, int size, BatchGenerationEnvironment genEnvironment, + DhChunkPos minPos, int widthInChunks, BatchGenerationEnvironment genEnvironment, EDhApiDistantGeneratorMode generatorMode, EDhApiWorldGenerationStep target, Consumer resultConsumer, ExecutorService worldGeneratorThreadPool) { - GenerationEvent generationEvent = new GenerationEvent(minPos, size, genEnvironment, generatorMode, target, resultConsumer); + GenerationEvent generationEvent = new GenerationEvent(minPos, widthInChunks, genEnvironment, generatorMode, target, resultConsumer); try { @@ -88,10 +86,6 @@ public final class GenerationEvent { try { - long runStartTime = System.nanoTime(); - generationEvent.timeoutTime = runStartTime; - generationEvent.inQueueTime = runStartTime - generationEvent.inQueueTime; - BatchGenerationEnvironment.isDhWorldGenThreadRef.set(true); @@ -168,35 +162,15 @@ public final class GenerationEvent } } - public boolean isComplete() { return this.future.isDone(); } - public boolean hasTimeout(int duration, TimeUnit unit) - { - if (this.timeoutTime == -1) - { - return false; - } - - long currentTime = System.nanoTime(); - long delta = currentTime - this.timeoutTime; - return (delta > TimeUnit.NANOSECONDS.convert(duration, unit)); - } - public boolean terminate() - { - LOGGER.info("======================DUMPING ALL THREADS FOR WORLD GEN======================="); - ThreadPoolUtil.WORLD_GEN_THREAD_FACTORY.dumpAllThreadStacks(); - this.future.cancel(true); - return this.future.isCancelled(); - } - - public void refreshTimeout() - { - this.timeoutTime = System.nanoTime(); - UncheckedInterruptedException.throwIfInterrupted(); - } + //================// + // base overrides // + //================// @Override public String toString() { return this.id + ":" + this.widthInChunks + "@" + this.minPos + "(" + this.targetGenerationStep + ")"; } + + } \ No newline at end of file