diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/VersionConstants.java b/common/src/main/java/com/seibel/lod/common/wrappers/VersionConstants.java index 837cd6ccd..e516efab0 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/VersionConstants.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/VersionConstants.java @@ -24,26 +24,12 @@ public class VersionConstants implements IVersionConstants { return 0; } - - @Override - public boolean isWorldGeneratorSingleThreaded(DistanceGenerationMode distanceGenerationMode) - { - return true; - } - + @Override public int getWorldGenerationCountPerThread() { return 1; } - - - @Override - public boolean hasBatchGenerationImplementation() - { - return true; - } - @Override public boolean isVanillaRenderedChunkSquare() diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/WrapperFactory.java b/common/src/main/java/com/seibel/lod/common/wrappers/WrapperFactory.java index 77b145c6e..d6839eb71 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/WrapperFactory.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/WrapperFactory.java @@ -26,11 +26,9 @@ import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper; import com.seibel.lod.core.wrapperInterfaces.chunk.AbstractChunkPosWrapper; import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper; import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvionmentWrapper; -import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractWorldGeneratorWrapper; import com.seibel.lod.common.wrappers.block.BlockPosWrapper; import com.seibel.lod.common.wrappers.chunk.ChunkPosWrapper; import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment; -import com.seibel.lod.common.wrappers.worldGeneration.WorldGeneratorWrapper; /** * This handles creating abstract wrapper objects. @@ -88,14 +86,6 @@ public class WrapperFactory implements IWrapperFactory return new ChunkPosWrapper(blockPos); } - - - @Override - public AbstractWorldGeneratorWrapper createWorldGenerator(LodBuilder newLodBuilder, LodDimension newLodDimension, IWorldWrapper worldWrapper) - { - return new WorldGeneratorWrapper(newLodBuilder, newLodDimension, worldWrapper); - } - public AbstractBatchGenerationEnvionmentWrapper createBatchGenerator(LodBuilder newLodBuilder, LodDimension newLodDimension, IWorldWrapper worldWrapper) { diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java index 00b3b9dd5..c136c7f86 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java @@ -208,7 +208,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper MinecraftClientWrapper.INSTANCE.sendChatMessage( "\u00A7eOverdraw prevention will be worse than normal."); } catch (Exception e2) {} - ApiShared.LOGGER.error("getVanillaRenderedChunks Error: {}", e); + ApiShared.LOGGER.error("getVanillaRenderedChunks Error: ", e); usingBackupGetVanillaRenderedChunks = true; } } diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index 142c859cf..5945ddee4 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -20,14 +20,13 @@ package com.seibel.lod.common.wrappers.worldGeneration; import com.seibel.lod.core.api.ApiShared; -import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.builders.lodBuilding.LodBuilder; import com.seibel.lod.core.builders.lodBuilding.LodBuilderConfig; import com.seibel.lod.core.enums.config.DistanceGenerationMode; import com.seibel.lod.core.enums.config.LightGenerationMode; import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler; import com.seibel.lod.core.objects.lod.LodDimension; -import com.seibel.lod.core.util.GridList; +import com.seibel.lod.core.util.gridList.ArrayGridList; import com.seibel.lod.core.util.LodThreadFactory; import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton; import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; @@ -191,7 +190,6 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv if (e.endNano != 0) { lodTime.add(e.endNano - preTime); - preTime = e.endNano; } } @@ -215,7 +213,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv //=================Generation Step=================== - public final LinkedList events = new LinkedList(); + public final LinkedList events = new LinkedList<>(); public final GlobalParameters params; public final StepStructureStart stepStructureStart = new StepStructureStart(this); public final StepStructureReference stepStructureReference = new StepStructureReference(this); @@ -230,12 +228,13 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv private static final IMinecraftClientWrapper MC = SingletonHandler.get(IMinecraftClientWrapper.class); public static final long EXCEPTION_TIMER_RESET_TIME = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); public static final int EXCEPTION_COUNTER_TRIGGER = 20; + public static final int RANGE_TO_RANGE_EMPTY_EXTENSION = 1; public int unknownExceptionCount = 0; public long lastExceptionTriggerTime = 0; public static final LodThreadFactory threadFactory = new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY); - public static ThreadLocal isDistantGeneratorThread = new ThreadLocal(); + public static ThreadLocal isDistantGeneratorThread = new ThreadLocal<>(); public static boolean isCurrentThreadDistantGeneratorThread() { return (isDistantGeneratorThread.get() != null); @@ -384,22 +383,20 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv if (ENABLE_EVENT_LOGGING) ApiShared.LOGGER.info("Lod Generate Event: " + e.pos); e.pEvent.beginNano = System.nanoTime(); - GridList referencedChunks; + ArrayGridList referencedChunks; + ArrayGridList genChunks; DistanceGenerationMode generationMode; LightedWorldGenRegion region; WorldGenLevelLightEngine lightEngine; LightGetterAdaptor adaptor; - + int refRange = e.range + RANGE_TO_RANGE_EMPTY_EXTENSION; + int refOffsetX = e.pos.x - refRange; + int refOffsetZ = e.pos.z - refRange; try { adaptor = new LightGetterAdaptor(params.level); lightEngine = new WorldGenLevelLightEngine(adaptor); - - int cx = e.pos.x; - int cy = e.pos.z; - int rangeEmpty = e.range + 1; - GridList chunks = new GridList(rangeEmpty); - + @SuppressWarnings("resource") EmptyChunkGenerator generator = (int x, int z) -> { @@ -418,23 +415,19 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv params.biomes, null); return target; }; - - for (int oy = -rangeEmpty; oy <= rangeEmpty; oy++) - { - for (int ox = -rangeEmpty; ox <= rangeEmpty; ox++) - { - ChunkAccess target = generator.generate(cx + ox, cy + oy); - chunks.add(target); - } - } + + referencedChunks = new ArrayGridList<>(refRange*2+1, + (x,z) -> generator.generate(x + refOffsetX,z + refOffsetZ) + ); e.pEvent.emptyNano = System.nanoTime(); e.refreshTimeout(); - region = new LightedWorldGenRegion(params.level, lightEngine, chunks, ChunkStatus.STRUCTURE_STARTS, rangeEmpty, e.lightMode, generator); + region = new LightedWorldGenRegion(params.level, lightEngine, referencedChunks, + ChunkStatus.STRUCTURE_STARTS, refRange, e.lightMode, generator); adaptor.setRegion(region); e.tParam.makeStructFeat(region); - referencedChunks = chunks.subGrid(e.range); - referencedChunks = generateDirect(e, referencedChunks, e.target, region); - + genChunks = new ArrayGridList<>(referencedChunks, RANGE_TO_RANGE_EMPTY_EXTENSION, + referencedChunks.gridSize - RANGE_TO_RANGE_EMPTY_EXTENSION); + generateDirect(e, genChunks, e.target, region); } catch (StepStructureStart.StructStartCorruptedException f) { @@ -466,14 +459,12 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv default: return; } - int centreIndex = referencedChunks.size() / 2; - for (int oy = -e.range; oy <= e.range; oy++) + for (int oy = 0; oy < genChunks.gridSize; oy++) { - for (int ox = -e.range; ox <= e.range; ox++) + for (int ox = 0; ox < genChunks.gridSize; ox++) { - int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); - ChunkAccess target = referencedChunks.get(targetIndex); + ChunkAccess target = genChunks.get(ox, oy); ChunkWrapper wrappedChunk = new ChunkWrapper(target, region); if (!wrappedChunk.isLightCorrect()) { throw new RuntimeException("The generated chunk somehow has isLightCorrect() returning false"); @@ -521,8 +512,8 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv } } - public GridList generateDirect(GenerationEvent e, GridList subRange, Steps step, - LightedWorldGenRegion region) + public void generateDirect(GenerationEvent e, ArrayGridList subRange, Steps step, + LightedWorldGenRegion region) { try { @@ -535,38 +526,37 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv } }); if (step == Steps.Empty) - return subRange; + return; stepStructureStart.generateGroup(e.tParam, region, subRange); e.pEvent.structStartNano = System.nanoTime(); e.refreshTimeout(); if (step == Steps.StructureStart) - return subRange; + return; stepStructureReference.generateGroup(e.tParam, region, subRange); e.pEvent.structRefNano = System.nanoTime(); e.refreshTimeout(); if (step == Steps.StructureReference) - return subRange; + return; stepBiomes.generateGroup(e.tParam, region, subRange); e.pEvent.biomeNano = System.nanoTime(); e.refreshTimeout(); if (step == Steps.Biomes) - return subRange; + return; stepNoise.generateGroup(e.tParam, region, subRange); e.pEvent.noiseNano = System.nanoTime(); e.refreshTimeout(); if (step == Steps.Noise) - return subRange; + return; stepSurface.generateGroup(e.tParam, region, subRange); e.pEvent.surfaceNano = System.nanoTime(); e.refreshTimeout(); if (step == Steps.Surface) - return subRange; + return; if (step == Steps.Carvers) - return subRange; + return; stepFeatures.generateGroup(e.tParam, region, subRange); e.pEvent.featureNano = System.nanoTime(); e.refreshTimeout(); - return subRange; } finally { diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGeneratorWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGeneratorWrapper.java deleted file mode 100644 index 599af6dcf..000000000 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGeneratorWrapper.java +++ /dev/null @@ -1,153 +0,0 @@ - -package com.seibel.lod.common.wrappers.worldGeneration; - -import com.seibel.lod.core.builders.lodBuilding.LodBuilder; -import com.seibel.lod.core.builders.lodBuilding.LodBuilderConfig; -import com.seibel.lod.core.enums.config.DistanceGenerationMode; -import com.seibel.lod.core.objects.lod.LodDimension; -import com.seibel.lod.core.wrapperInterfaces.chunk.AbstractChunkPosWrapper; -import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper; -import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractWorldGeneratorWrapper; - -import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; -import com.seibel.lod.common.wrappers.world.WorldWrapper; - -import net.minecraft.world.level.chunk.*; -/* */ -/* */ import net.minecraft.server.level.ServerLevel; -/* */ -/* */ -/* */ -/* */ -/* */ -/* */ -/* */ -/* */ -/* */ - -/** - * @author James Seibel - * @version 11-13-2021 - */ -public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper -{ - public final ServerLevel serverWorld; - public final LodDimension lodDim; - public final LodBuilder lodBuilder; - - public WorldGeneratorWrapper(LodBuilder newLodBuilder, LodDimension newLodDimension, IWorldWrapper worldWrapper) - { - super(newLodBuilder, newLodDimension, worldWrapper); - - lodBuilder = newLodBuilder; - lodDim = newLodDimension; - serverWorld = ((WorldWrapper) worldWrapper).getServerWorld(); - } - - /** takes about 2-5 ms */ - @Override - public void generateBiomesOnly(AbstractChunkPosWrapper pos, DistanceGenerationMode generationMode) - { - generate(pos.getX(), pos.getZ(), generationMode); - } - - /** takes about 10 - 20 ms */ - @Override - public void generateSurface(AbstractChunkPosWrapper pos) - { - generate(pos.getX(), pos.getZ(), DistanceGenerationMode.SURFACE); - } - - /** - * takes about 15 - 20 ms - */ - @Override - public void generateFeatures(AbstractChunkPosWrapper pos) - { - generate(pos.getX(), pos.getZ(), DistanceGenerationMode.FEATURES); - } - - /** - * Generates using MC's ServerWorld. - *

- * on pre generated chunks 0 - 1 ms
- * on un generated chunks 0 - 50 ms
- * with the median seeming to hover around 15 - 30 ms
- * and outliers in the 100 - 200 ms range
- *

- * Note this should not be multithreaded and does cause server/simulation lag - * (Higher lag for generating than loading) - */ - @Override - public void generateFull(AbstractChunkPosWrapper pos) - { - generate(pos.getX(), pos.getZ(), DistanceGenerationMode.FULL); - } - - private void generate(int chunkX, int chunkZ, DistanceGenerationMode generationMode) - { - - // long t = System.nanoTime(); - - ChunkStatus targetStatus; - switch (generationMode) - { - case BIOME_ONLY: - targetStatus = ChunkStatus.BIOMES; - break; - case BIOME_ONLY_SIMULATE_HEIGHT: - targetStatus = ChunkStatus.NOISE; - break; - case SURFACE: - targetStatus = ChunkStatus.SURFACE; - break; - case FEATURES: - targetStatus = ChunkStatus.FEATURES; - break; - case FULL: - targetStatus = ChunkStatus.FULL; - break; - case NONE: - default: - return; - } - - // The bool=true means that we wants to generate chunk, and that the returned ChunkAccess must not be null - ChunkAccess ca = serverWorld.getChunkSource().getChunk(chunkX, chunkZ, targetStatus, true); - if (ca == null) - throw new RuntimeException("This should NEVER be null due to bool being true"); - lodBuilder.generateLodNodeFromChunk(lodDim, new ChunkWrapper(ca, serverWorld), new LodBuilderConfig(generationMode), false, true); - - // long duration = System.nanoTime()-t; - - // Debug print the duration - // System.out.println("LodChunkGenFull["+chunkX+","+chunkZ+"]: "+(double)(duration)/1000.); - - } - - /* TODO: Update this chart - * performance/generation tests related to - * serverWorld.getChunk(x, z, ChunkStatus. *** ) - - true/false is whether they generated blocks or not - the time is how long it took to generate - - ChunkStatus.EMPTY 0 - 1 ms false (empty, what did you expect? :P) - ChunkStatus.STRUCTURE_REFERENCES 1 - 2 ms false (no height, only generates some chunks) - ChunkStatus.BIOMES 1 - 10 ms false (no height) - ChunkStatus.NOISE 4 - 15 ms true (all blocks are stone) - ChunkStatus.LIQUID_CARVERS 6 - 12 ms true (no snow/trees, just grass) - ChunkStatus.SURFACE 5 - 15 ms true (no snow/trees, just grass) - ChunkStatus.CARVERS 5 - 30 ms true (no snow/trees, just grass) - ChunkStatus.FEATURES 7 - 25 ms true - ChunkStatus.HEIGHTMAPS 20 - 40 ms true - ChunkStatus.LIGHT 20 - 40 ms true - ChunkStatus.FULL 30 - 50 ms true - ChunkStatus.SPAWN 50 - 80 ms true - - At this point I would suggest using FEATURES, as it generates snow and trees - (and any other object that are needed to make biomes distinct) - - Otherwise, if snow/trees aren't necessary SURFACE is the next fastest (although not by much) - */ -} \ No newline at end of file diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepFeatures.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepFeatures.java index ee14b5ee5..a17fa172e 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepFeatures.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepFeatures.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment; import com.seibel.lod.common.wrappers.worldGeneration.ThreadedParameters; -import com.seibel.lod.core.util.GridList; +import com.seibel.lod.core.util.gridList.ArrayGridList; import net.minecraft.ReportedException; import net.minecraft.server.level.WorldGenRegion; @@ -30,7 +30,7 @@ public final class StepFeatures { public final ChunkStatus STATUS = ChunkStatus.FEATURES; public void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, - GridList chunks) { + ArrayGridList chunks) { ArrayList chunksToDo = new ArrayList(); for (ChunkAccess chunk : chunks) { diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepLight.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepLight.java index b2d1a84bd..90ef6ef5b 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepLight.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepLight.java @@ -2,7 +2,7 @@ package com.seibel.lod.common.wrappers.worldGeneration.step; import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment; import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.WorldGenLevelLightEngine; -import com.seibel.lod.core.util.GridList; +import com.seibel.lod.core.util.gridList.ArrayGridList; import net.minecraft.server.level.ThreadedLevelLightEngine; import net.minecraft.world.level.chunk.ChunkAccess; @@ -28,7 +28,7 @@ public final class StepLight { public final ChunkStatus STATUS = ChunkStatus.LIGHT; public void generateGroup(LightEventListener lightEngine, - GridList chunks) { + ArrayGridList chunks) { //ArrayList chunksToDo = new ArrayList(); for (ChunkAccess chunk : chunks) { diff --git a/core b/core index 2907c8e3e..804738cfe 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 2907c8e3e7bbbe570328057b41c2baf116ddec37 +Subproject commit 804738cfe5eb7ce4312bf6cd84e559bb3f6127db