From e71660eb4153cd27e070600b446eca6771b70369 Mon Sep 17 00:00:00 2001 From: tom lee Date: Wed, 5 Jan 2022 19:17:31 +0800 Subject: [PATCH] Fixed generation issues and buffer now update more aggresively --- .../worldGeneration/LodWorldGenerator.java | 9 +++- .../lod/core/objects/lod/LodDimension.java | 44 ++++--------------- .../lod/core/objects/lod/LodRegion.java | 31 ++----------- 3 files changed, 21 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java index cddd755f6..4baa4bc30 100644 --- a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java +++ b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java @@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.seibel.lod.core.builders.lodBuilding.LodBuilder; import com.seibel.lod.core.enums.config.DistanceGenerationMode; +import com.seibel.lod.core.enums.config.GenerationPriority; import com.seibel.lod.core.objects.PosToGenerateContainer; import com.seibel.lod.core.objects.lod.LodDimension; import com.seibel.lod.core.util.LevelPosUtil; @@ -115,6 +116,10 @@ public class LodWorldGenerator // This is fine currently since DistanceGenerationMode doesn't care about the detail level for now. // However, If that was to be changed, This will need to be fixed. DistanceGenerationMode mode = CONFIG.client().worldGenerator().getDistanceGenerationMode(); + final GenerationPriority priority; + if (CONFIG.client().worldGenerator().getGenerationPriority() == GenerationPriority.AUTO) + priority = MC.hasSinglePlayerServer() ? GenerationPriority.FAR_FIRST : GenerationPriority.NEAR_FIRST; + else priority = CONFIG.client().worldGenerator().getGenerationPriority(); if (mode != DistanceGenerationMode.NONE && !generatorThreadRunning @@ -192,7 +197,9 @@ public class LodWorldGenerator // add the far positions - if (farIndex < posToGenerate.getNumberOfFarPos() && posToGenerate.getNthDetail(farIndex, false) != 0) + // But if priority is NEAR_FIRST, we only do that if near pos has ran out. + if ((nearIndex >= posToGenerate.getNumberOfNearPos() || priority != GenerationPriority.NEAR_FIRST) && + farIndex < posToGenerate.getNumberOfFarPos() && posToGenerate.getNthDetail(farIndex, false) != 0) { detailLevel = (byte) (posToGenerate.getNthDetail(farIndex, false) - 1); posX = posToGenerate.getNthPosX(farIndex, false); diff --git a/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java b/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java index e77fbd412..8c5aa7f2c 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java @@ -443,7 +443,13 @@ public class LodDimension region.getMinDetailLevel() > minDetail) { regions[x][z] = getRegionFromFile(regions[x][z], minDetail, generationMode, verticalQuality); updated = true; + } else if (region.lastMaxDetailLevel != maxDetail) { + region.lastMaxDetailLevel = maxDetail; + updated = true; + } else if (region.lastMaxDetailLevel != region.getMinDetailLevel()) { + updated = true; } + if (updated) { regenRegionBuffer[x][z] = 2; regenDimensionBuffers = true; @@ -555,45 +561,13 @@ public class LodDimension public PosToGenerateContainer getPosToGenerate(int maxDataToGenerate, int playerBlockPosX, int playerBlockPosZ) { PosToGenerateContainer posToGenerate; - LodRegion lodRegion; - // all the following values are used for the spiral matrix visit - // x and z are the matrix coord - // dx and dz is the next move on the coordinate in the range -1 0 +1 - int x, z, dx, dz, t; - x = 0; - z = 0; - dx = 0; - dz = -1; - - //in the FAR_FIRST generation we dedicate part of the generation process to the far region with really - //low detail quality. - posToGenerate = new PosToGenerateContainer((byte) 8, maxDataToGenerate, playerBlockPosX, playerBlockPosZ); - - int xRegion; - int zRegion; - - for (int i = 0; i < width * width; i++) - { - xRegion = x + center.x; - zRegion = z + center.z; - + iterateWithSpiral((int x, int z) -> { //All of this is handled directly by the region, which scan every pos from top to bottom of the quad tree - lodRegion = getRegion(xRegion, zRegion); + LodRegion lodRegion = regions[x][z]; if (lodRegion != null) lodRegion.getPosToGenerate(posToGenerate, playerBlockPosX, playerBlockPosZ); - - - //with this code section we find the next chunk to check - if ((x == z) || ((x < 0) && (x == -z)) || ((x > 0) && (x == 1 - z))) - { - t = dx; - dx = -dz; - dz = t; - } - x += dx; - z += dz; - } + }); return posToGenerate; } diff --git a/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java b/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java index 5c48ba045..304444c1d 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/LodRegion.java @@ -47,6 +47,7 @@ public class LodRegion /** Holds the lowest (least detailed) detail level in this region */ private byte minDetailLevel; + public byte lastMaxDetailLevel = LodUtil.REGION_DETAIL_LEVEL; /** * This holds all data for this region @@ -75,7 +76,6 @@ public class LodRegion this.generationMode = generationMode; dataContainer = new LevelContainer[POSSIBLE_LOD]; - // Initialize all the different matrices for (byte lod = minDetailLevel; lod <= LodUtil.REGION_DETAIL_LEVEL; lod++) { @@ -248,7 +248,7 @@ public class LodRegion int size = 1 << (LodUtil.REGION_DETAIL_LEVEL - detailLevel); // calculate what LevelPos are in range to generate - int minDistance = LevelPosUtil.minDistance(detailLevel, childOffsetPosX, childOffsetPosZ, playerPosX, playerPosZ, regionPosX, regionPosZ); + int minDistance = LevelPosUtil.minDistance(LodUtil.REGION_DETAIL_LEVEL, regionPosX, regionPosZ, playerPosX, playerPosZ); // determine this child's levelPos byte childDetailLevel = (byte) (detailLevel - 1); @@ -273,36 +273,13 @@ public class LodRegion if (detailLevel > LodUtil.CHUNK_DETAIL_LEVEL) { - int ungeneratedChildren = 0; - - // make sure all children are generated to this detailLevel for (int x = 0; x <= 1; x++) - { for (int z = 0; z <= 1; z++) - { - if (!doesDataExist(childDetailLevel, childPosX + x, childPosZ + z)) - { - ungeneratedChildren++; - posToGenerate.addPosToGenerate(childDetailLevel, childPosX + x + regionPosX * childSize, childPosZ + z + regionPosZ * childSize); - } - } - } - - // only if all the children are correctly generated - // should we go deeper - if (ungeneratedChildren == 0) - for (int x = 0; x <= 1; x++) - for (int z = 0; z <= 1; z++) - getPosToGenerate(posToGenerate, childDetailLevel, childPosX + x, childPosZ + z, playerPosX, playerPosZ); + getPosToGenerate(posToGenerate, childDetailLevel, childPosX + x, childPosZ + z, playerPosX, playerPosZ); } else { - // The detail Level is smaller than a chunk. - // Only recurse down the top right child. - if (!doesDataExist(childDetailLevel, childPosX, childPosZ)) - posToGenerate.addPosToGenerate(childDetailLevel, childPosX + regionPosX * childSize, childPosZ + regionPosZ * childSize); - else - getPosToGenerate(posToGenerate, childDetailLevel, childPosX, childPosZ, playerPosX, playerPosZ); + getPosToGenerate(posToGenerate, childDetailLevel, childPosX, childPosZ, playerPosX, playerPosZ); } } }