diff --git a/coreSubProjects b/coreSubProjects index a98955530..c7c5ab17b 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit a98955530fbe75a5c30cd97050aa42d68834aa0a +Subproject commit c7c5ab17bc489d7d05da46f76cf410ad2903f395 diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestWorldGenerator.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestWorldGenerator.java index d5cf9d578..825859e89 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestWorldGenerator.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/testing/TestWorldGenerator.java @@ -11,17 +11,29 @@ import com.seibel.distanthorizons.api.objects.data.DhApiChunk; import com.seibel.distanthorizons.api.objects.data.DhApiTerrainDataPoint; import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; +import com.seibel.distanthorizons.core.config.Config; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.ChunkAccess; import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicInteger; public class TestWorldGenerator extends AbstractDhApiChunkWorldGenerator { + private static final int MAX_QUEUED_TASKS_PER_THREAD = 10; + private final ServerLevel level; private final IDhApiLevelWrapper levelWrapper; + private final AtomicInteger genCountRef = new AtomicInteger(0); + + + + //=============// + // constructor // + //=============// + public TestWorldGenerator(ServerLevel level) { this.level = level; @@ -29,12 +41,30 @@ public class TestWorldGenerator extends AbstractDhApiChunkWorldGenerator } + + //============// + // properties // + //============// + @Override public EDhApiWorldGeneratorReturnType getReturnType() { return EDhApiWorldGeneratorReturnType.API_CHUNKS; } @Override - public boolean isBusy() { return false; } + public boolean isBusy() + { + int worldGenThreadCount = Math.max(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads.get(), 1); + int maxWorldGenTaskCount = worldGenThreadCount * MAX_QUEUED_TASKS_PER_THREAD; + return this.genCountRef.get() > maxWorldGenTaskCount; + } + @Override + public boolean runApiChunkValidation() { return true; } + + + + //==================// + // chunk generation // + //==================// @Override public Object[] generateChunk(int chunkX, int chunkZ, EDhApiDistantGeneratorMode eDhApiDistantGeneratorMode) @@ -46,44 +76,60 @@ public class TestWorldGenerator extends AbstractDhApiChunkWorldGenerator @Override public DhApiChunk generateApiChunk(int chunkPosX, int chunkPosZ, EDhApiDistantGeneratorMode generatorMode) { - // this test is only validated for 1.18.2 and up - // (and it is only needed when testing world gen overrides/API chunks, so it isn't normally needed) - #if MC_VER >= MC_1_18_2 - ChunkAccess chunk = this.level.getChunk(chunkPosX, chunkPosZ); - ChunkWrapper chunkWrapper = new ChunkWrapper(chunk, null, null); - - int minBuildHeight = chunkWrapper.getMinBuildHeight(); - int maxBuildHeight = chunkWrapper.getMaxBuildHeight(); - - DhApiChunk apiChunk = DhApiChunk.create(chunkPosX, chunkPosZ, minBuildHeight, maxBuildHeight); - for (int x = 0; x < 16; x++) + try { - for (int z = 0; z < 16; z++) + this.genCountRef.incrementAndGet(); + + + // this test is only validated for 1.18.2 and up + // (and it is only needed when testing world gen overrides/API chunks, so it isn't normally needed) + #if MC_VER >= MC_1_18_2 + ChunkAccess chunk = this.level.getChunk(chunkPosX, chunkPosZ); + + + int minBuildHeight = this.level.getMinBuildHeight(); + int maxBuildHeight = this.level.getMaxBuildHeight(); + + DhApiChunk apiChunk = DhApiChunk.create(chunkPosX, chunkPosZ, minBuildHeight, maxBuildHeight); + for (int x = 0; x < 16; x++) { - ArrayList dataPoints = new ArrayList<>(); - - IDhApiBlockStateWrapper block = null; - IDhApiBiomeWrapper biome = null; - - for (int y = minBuildHeight; y < maxBuildHeight; y++) + for (int z = 0; z < 16; z++) { - block = DhApi.Delayed.wrapperFactory.getBlockStateWrapper(new Object[]{chunk.getBlockState(new BlockPos(x, y, z))}, this.levelWrapper); - biome = DhApi.Delayed.wrapperFactory.getBiomeWrapper(new Object[]{chunk.getNoiseBiome(x, y, z)}, this.levelWrapper); - dataPoints.add(DhApiTerrainDataPoint.create((byte) 0, 0, 15, y, y + 1, block, biome)); + ArrayList dataPoints = new ArrayList<>(); + + IDhApiBlockStateWrapper block = null; + IDhApiBiomeWrapper biome = null; + + for (int y = minBuildHeight; y < maxBuildHeight; y++) + { + block = DhApi.Delayed.wrapperFactory.getBlockStateWrapper(new Object[]{chunk.getBlockState(new BlockPos(x, y, z))}, this.levelWrapper); + biome = DhApi.Delayed.wrapperFactory.getBiomeWrapper(new Object[]{chunk.getNoiseBiome(x, y, z)}, this.levelWrapper); + dataPoints.add(DhApiTerrainDataPoint.create((byte) 0, 0, 15, y, y + 1, block, biome)); + } + + apiChunk.setDataPoints(x, z, dataPoints); } - - apiChunk.setDataPoints(x, z, dataPoints); } + return apiChunk; + #else + return null; + #endif + } + finally + { + this.genCountRef.decrementAndGet(); } - return apiChunk; - #else - return null; - #endif } @Override public void preGeneratorTaskStart() { /* do nothing */ } + + + //=========// + // cleanup // + //=========// + @Override public void close() { /* do nothing */ }