From a38e7a00e45df746a513fb972500744e486780a4 Mon Sep 17 00:00:00 2001 From: tom lee Date: Mon, 24 Jan 2022 21:07:48 +0800 Subject: [PATCH] Update core, Change some small stuff. --- .../wrappers/block/BlockColorWrapper.java | 13 +++++----- .../wrappers/block/BlockShapeWrapper.java | 13 +++++----- .../common/wrappers/chunk/ChunkWrapper.java | 1 + .../ExperimentalGenerator.java | 24 +++++++++++++++---- .../worldGeneration/WorldGenerationStep.java | 22 ++++++++++++++--- core | 2 +- 6 files changed, 53 insertions(+), 22 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockColorWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockColorWrapper.java index fb12a945f..4dfd541ee 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockColorWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockColorWrapper.java @@ -80,16 +80,15 @@ public class BlockColorWrapper implements IBlockColorWrapper public static IBlockColorWrapper getBlockColorWrapper(Block block) { //first we check if the block has already been wrapped - if (blockColorWrapperMap.containsKey(block) && blockColorWrapperMap.get(block) != null) - return blockColorWrapperMap.get(block); - + BlockColorWrapper colorWrapper = blockColorWrapperMap.get(block); + if (colorWrapper != null) + return colorWrapper; //if it hasn't been created yet, we create it and save it in the map - BlockColorWrapper blockWrapper = new BlockColorWrapper(block); - blockColorWrapperMap.put(block, blockWrapper); - + colorWrapper = new BlockColorWrapper(block); + BlockColorWrapper colorWrapperCAS = blockColorWrapperMap.putIfAbsent(block, colorWrapper); //we return the newly created wrapper - return blockWrapper; + return colorWrapperCAS==null ? colorWrapper : colorWrapperCAS; } /** diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockShapeWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockShapeWrapper.java index 470f2bef9..b25991ff4 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockShapeWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockShapeWrapper.java @@ -58,16 +58,15 @@ public class BlockShapeWrapper implements IBlockShapeWrapper static public BlockShapeWrapper getBlockShapeWrapper(Block block, ChunkWrapper chunkWrapper, int x, int y, int z) { //first we check if the block has already been wrapped - if (blockShapeWrapperMap.containsKey(block) && blockShapeWrapperMap.get(block) != null) - return blockShapeWrapperMap.get(block); - + BlockShapeWrapper blockWrapper = blockShapeWrapperMap.get(block); + if (blockWrapper != null) + return blockWrapper; //if it hasn't been created yet, we create it and save it in the map - BlockShapeWrapper blockWrapper = new BlockShapeWrapper(block, chunkWrapper, x, y, z); - blockShapeWrapperMap.put(block, blockWrapper); - + blockWrapper = new BlockShapeWrapper(block, chunkWrapper, x, y, z); + BlockShapeWrapper blockWrapperCAS = blockShapeWrapperMap.putIfAbsent(block, blockWrapper); //we return the newly created wrapper - return blockWrapper; + return blockWrapperCAS==null ? blockWrapper : blockWrapperCAS; } private void setupShapes(IChunkWrapper chunkWrapper, int x, int y, int z) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/chunk/ChunkWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/chunk/ChunkWrapper.java index b814a029c..9d774ed7c 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/chunk/ChunkWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/chunk/ChunkWrapper.java @@ -13,6 +13,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.QuartPos; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.block.AirBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlockContainer; diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java index 3eaece9bd..1dfed7493 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java @@ -47,9 +47,10 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra public LodDimension targetLodDim; public static final int generationGroupSize = 4; public static final int generationGroupSizeFar = 0; - public static int numberOfGenerationPoints = CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(); + public static int previousThreadCount = CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(); private int estimatedSampleNeeded = 128; + private int estimatedPointsToQueue = 1; public ExperimentalGenerator(LodBuilder newLodBuilder, LodDimension newLodDimension, IWorldWrapper worldWrapper) { super(newLodBuilder, newLodDimension, worldWrapper); @@ -73,7 +74,13 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra } DistanceGenerationMode mode = CONFIG.client().worldGenerator().getDistanceGenerationMode(); - numberOfGenerationPoints = CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(); + int newThreadCount = CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(); + if (newThreadCount != previousThreadCount) { + generationGroup.resizeThreadPool(newThreadCount); + previousThreadCount = newThreadCount; + } + if (estimatedPointsToQueue < newThreadCount) estimatedPointsToQueue = newThreadCount; + GenerationPriority priority = CONFIG.client().worldGenerator().getGenerationPriority(); if (priority == GenerationPriority.AUTO) priority = MC.hasSinglePlayerServer() ? GenerationPriority.FAR_FIRST : GenerationPriority.NEAR_FIRST; @@ -83,10 +90,14 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra return; int eventsCount = generationGroup.events.size(); // If we still all jobs running, return. - if (eventsCount >= numberOfGenerationPoints) + if (eventsCount >= estimatedPointsToQueue) { + estimatedPointsToQueue--; + if (estimatedPointsToQueue < newThreadCount) estimatedPointsToQueue = newThreadCount; return; + } + - final int targetToGenerate = numberOfGenerationPoints - eventsCount; + final int targetToGenerate = estimatedPointsToQueue - eventsCount; int toGenerate = targetToGenerate; int positionGoneThough = 0; @@ -98,6 +109,11 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra // position generation is completed. PosToGenerateContainer posToGenerate = lodDim.getPosToGenerate(estimatedSampleNeeded, playerPosX, playerPosZ, priority, mode); + if (eventsCount == 0 && posToGenerate.getNumberOfPos()>=estimatedSampleNeeded) { + estimatedPointsToQueue++; + if (estimatedPointsToQueue > newThreadCount*10) estimatedPointsToQueue = newThreadCount*10; + } + //ClientApi.LOGGER.info("PosToGenerate: {}", posToGenerate); // Find the max number of iterations we need to go though. diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java index 4545ddd1b..1330b2378 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java @@ -26,6 +26,8 @@ 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.util.LodThreadFactory; +import com.seibel.lod.core.util.SingletonHandler; +import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton; import com.seibel.lod.core.wrapperInterfaces.modAccessor.IStarlightAccessor; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -461,10 +463,20 @@ public final class WorldGenerationStep { final StepCarvers stepCarvers = new StepCarvers(); final StepFeatures stepFeatures = new StepFeatures(); final StepLight stepLight = new StepLight(); + private static final ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class); - public final ExecutorService executors = Executors - .newCachedThreadPool(new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY)); + //public final ExecutorService executors = Executors + // .newCachedThreadPool(new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY)); + public ExecutorService executors = Executors + .newFixedThreadPool(CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(), + new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY)); + public void resizeThreadPool(int newThreadCount) + { + executors = Executors.newFixedThreadPool(newThreadCount, + new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY)); + } + public boolean tryAddPoint(int px, int pz, int range, Steps target) { int boxSize = range * 2 + 1; int x = Math.floorDiv(px, boxSize) * boxSize + range; @@ -621,7 +633,7 @@ public final class WorldGenerationStep { int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); ChunkAccess target = referencedChunks.get(targetIndex); params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), new LodBuilderConfig(generationMode) - , false); + , true); //params.lodBuilder.generateLodNodeAsync(new ChunkWrapper(target, region), ApiShared.lodWorld, params.lodDim.dimension, // generationMode, false, () -> {}, () -> {}); } @@ -1281,5 +1293,9 @@ public final class WorldGenerationStep { throw new UnsupportedOperationException("This should never be used!"); } } + + + + } diff --git a/core b/core index ab3880a5e..c3abb9c46 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit ab3880a5e56b7238522fd598696e9fe5ee2f67b6 +Subproject commit c3abb9c46b4d60d84508837c89bcea75b1b6de6e