From 98327e6fdfd13423432693cb6deaf92517fe88cc Mon Sep 17 00:00:00 2001 From: tom lee Date: Tue, 25 Jan 2022 17:08:55 +0800 Subject: [PATCH] Update core + Config Wrapper --- .../java/com/seibel/lod/common/Config.java | 20 +++++- .../config/LodConfigWrapperSingleton.java | 30 +++++++-- .../ExperimentalGenerator.java | 9 +-- .../worldGeneration/WorldGenerationStep.java | 63 ++++++++++--------- core | 2 +- 5 files changed, 84 insertions(+), 40 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/Config.java b/common/src/main/java/com/seibel/lod/common/Config.java index 80a610c90..a8a208284 100644 --- a/common/src/main/java/com/seibel/lod/common/Config.java +++ b/common/src/main/java/com/seibel/lod/common/Config.java @@ -199,10 +199,12 @@ public class Config extends ConfigGui @ConfigAnnotations.Entry public static boolean useExtendedNearClipPlane = IAdvancedGraphics.USE_EXTENDED_NEAR_CLIP_PLANE_DEFAULT; + /* @ConfigAnnotations.FileComment public static String _backsideCullingRange = IAdvancedGraphics.VANILLA_CULLING_RANGE_DESC; @ConfigAnnotations.Entry(minValue = 0, maxValue = 512) public static int backsideCullingRange = IAdvancedGraphics.VANILLA_CULLING_RANGE_MIN_DEFAULT_MAX.defaultValue; + */ } } @@ -210,21 +212,33 @@ public class Config extends ConfigGui public static class WorldGenerator { @ConfigAnnotations.FileComment - public static String _generationPriority = IWorldGenerator.GENERATION_PRIORITY_DESC; + public static String _enableDistantGeneration = IWorldGenerator.ENABLE_DISTANT_GENERATION_DESC; @ConfigAnnotations.Entry - public static GenerationPriority generationPriority = IWorldGenerator.GENERATION_PRIORITY_DEFAULT; + public static boolean enableDistantGeneration = IWorldGenerator.ENABLE_DISTANT_GENERATION_DEFAULT; // @ConfigAnnotations.FileComment // public static String _distanceGenerationMode = IWorldGenerator.getDistanceGenerationModeDesc(); @ConfigAnnotations.Entry public static DistanceGenerationMode distanceGenerationMode = IWorldGenerator.DISTANCE_GENERATION_MODE_DEFAULT; + + @ConfigAnnotations.FileComment + public static String _lightGenerationMode = IWorldGenerator.LIGHT_GENERATION_MODE_DESC; + @ConfigAnnotations.Entry + public static LightGenerationMode lightGenerationMode = IWorldGenerator.LIGHT_GENERATION_MODE_DEFAULT; + + @ConfigAnnotations.FileComment + public static String _generationPriority = IWorldGenerator.GENERATION_PRIORITY_DESC; + @ConfigAnnotations.Entry + public static GenerationPriority generationPriority = IWorldGenerator.GENERATION_PRIORITY_DEFAULT; + /* @ConfigAnnotations.FileComment public static String _allowUnstableFeatureGeneration = IWorldGenerator.ALLOW_UNSTABLE_FEATURE_GENERATION_DESC; // FIXME: Temperary override. In 1.18, the newer Unstable gnerator is more usable @ConfigAnnotations.Entry public static boolean allowUnstableFeatureGeneration = true;//IWorldGenerator.ALLOW_UNSTABLE_FEATURE_GENERATION_DEFAULT; - + */ + @ConfigAnnotations.FileComment public static String _blocksToAvoid = IWorldGenerator.BLOCKS_TO_AVOID_DESC; @ConfigAnnotations.Entry diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java b/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java index 24416572f..ddaeb46ad 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java @@ -349,7 +349,7 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.vanillaOverdraw").value = newVanillaOverdraw; ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.vanillaOverdraw"); } - + /* @Override public int getBacksideCullingRange() { @@ -360,7 +360,7 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton { ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.backsideCullingRange").value = newBacksideCullingRange; ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.backsideCullingRange"); - } + }*/ @Override public boolean getUseExtendedNearClipPlane() @@ -409,7 +409,7 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton ConfigGui.editSingleOption.saveOption("client.worldGenerator.distanceGenerationMode"); } - + /* @Override public boolean getAllowUnstableFeatureGeneration() { @@ -420,7 +420,7 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton { ConfigGui.editSingleOption.getEntry("client.worldGenerator.allowUnstableFeatureGeneration").value = newAllowUnstableFeatureGeneration; ConfigGui.editSingleOption.saveOption("client.worldGenerator.allowUnstableFeatureGeneration"); - } + }*/ @Override @@ -434,6 +434,28 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton ConfigGui.editSingleOption.getEntry("client.worldGenerator.blocksToAvoid").value = newBlockToAvoid; ConfigGui.editSingleOption.saveOption("client.worldGenerator.blocksToAvoid"); } + @Override + public boolean getEnableDistantGeneration() + { + return Config.Client.WorldGenerator.enableDistantGeneration; + } + @Override + public void setEnableDistantGeneration(boolean newEnableDistantGeneration) + { + ConfigGui.editSingleOption.getEntry("client.worldGenerator.enableDistantGeneration").value = newEnableDistantGeneration; + ConfigGui.editSingleOption.saveOption("client.worldGenerator.enableDistantGeneration"); + } + @Override + public LightGenerationMode getLightGenerationMode() + { + return Config.Client.WorldGenerator.lightGenerationMode; + } + @Override + public void setLightGenerationMode(LightGenerationMode newLightGenerationMode) + { + ConfigGui.editSingleOption.getEntry("client.worldGenerator.lightGenerationMode").value = newLightGenerationMode; + ConfigGui.editSingleOption.saveOption("client.worldGenerator.lightGenerationMode"); + } } 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 005003168..e39ddf71e 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 @@ -85,7 +85,7 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra priority = MC.hasSinglePlayerServer() ? GenerationPriority.FAR_FIRST : GenerationPriority.NEAR_FIRST; generationGroup.updateAllFutures(); - if (mode == DistanceGenerationMode.NONE || !MC.hasSinglePlayerServer()) + if (!MC.hasSinglePlayerServer()) return; int eventsCount = generationGroup.events.size(); // If we still all jobs running, return. @@ -122,8 +122,8 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra Steps targetStep; switch (mode) { case NONE: - case FULL: - return; + targetStep = Steps.Empty; //NOTE: Only load in existing chunks. No new chunk generation + break; case BIOME_ONLY: targetStep = Steps.Biomes; //NOTE: No block. Require fake height in LodBuilder break; @@ -134,6 +134,7 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra targetStep = Steps.Surface; //Carvers or Surface??? break; case FEATURES: + case FULL: targetStep = Steps.Features; break; // TODO! @@ -144,7 +145,7 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra if (ENABLE_GENERATOR_STATS_LOGGING) ClientApi.LOGGER.info("WorldGen. Near:"+posToGenerate.getNumberOfNearPos()+" Far:"+posToGenerate.getNumberOfFarPos()); - if (priority == GenerationPriority.FAR_FIRST) { + if (priority == GenerationPriority.FAR_FIRST || priority == GenerationPriority.BALANCED) { int nearCount = posToGenerate.getNumberOfNearPos(); int farCount = posToGenerate.getNumberOfFarPos(); 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 3d077f15a..a823a292f 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 @@ -24,6 +24,7 @@ import com.seibel.lod.core.api.ModAccessorApi; 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.objects.lod.LodDimension; import com.seibel.lod.core.util.LodThreadFactory; import com.seibel.lod.core.util.SingletonHandler; @@ -71,6 +72,7 @@ import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.DataLayer; +import net.minecraft.world.level.chunk.ImposterProtoChunk; import net.minecraft.world.level.chunk.LevelChunkSection; import net.minecraft.world.level.chunk.LightChunkGetter; import net.minecraft.world.level.chunk.ProtoChunk; @@ -119,9 +121,7 @@ Lod Generation: 0.269023348s public final class WorldGenerationStep { public static final boolean ENABLE_PERF_LOGGING = false; public static final boolean ENABLE_EVENT_LOGGING = true; - //TODO: Make this LightMode a config //TODO: Make actual proper support for StarLight - public static final LightMode DEFAULT_LIGHTMODE = LightMode.Fancy; //FIXME: Move this outside the WorldGenerationStep thingy public static class Rolling { @@ -229,10 +229,6 @@ public final class WorldGenerationStep { enum Steps { Empty, StructureStart, StructureReference, Biomes, Noise, Surface, Carvers, LiquidCarvers, Features, Light, } - - enum LightMode { - Fancy, Fast, Step, StarLight - } //FIXME: Remove this and use the Utils one public static final class GridList extends ArrayList implements List { @@ -380,7 +376,7 @@ public final class WorldGenerationStep { long nanotime; final int id; final Steps target; - final LightMode lightMode; + final LightGenerationMode lightMode; final PrefEvent pEvent = new PrefEvent(); public GenerationEvent(ChunkPos pos, int range, WorldGenerationStep generationGroup, Steps target) { @@ -390,8 +386,9 @@ public final class WorldGenerationStep { id = generationFutureDebugIDs++; this.target = target; this.tParam = ThreadedParameters.getOrMake(generationGroup.params); - LightMode mode = DEFAULT_LIGHTMODE; - if (ModAccessorApi.get(IStarlightAccessor.class) != null) mode = LightMode.StarLight; + LightGenerationMode mode = CONFIG.client().worldGenerator().getLightGenerationMode(); + + this.lightMode = mode; future = generationGroup.executors.submit(() -> { @@ -541,6 +538,7 @@ public final class WorldGenerationStep { boolean bl = compoundTag.contains("Status", 8); if (bl) { ProtoChunk chunkAccess = ChunkSerializer.read(level, level.getPoiManager(), chunkPos, compoundTag); + level.getLightEngine().retainData(chunkAccess.getPos(), false); return chunkAccess; } ClientApi.LOGGER.error("DistantHorizons: Chunk file at {} is missing level data, skipping", chunkPos); @@ -603,11 +601,13 @@ public final class WorldGenerationStep { } switch (e.target) { + case Empty: case StructureStart: case StructureReference: generationMode = DistanceGenerationMode.NONE; break; case Biomes: + generationMode = DistanceGenerationMode.BIOME_ONLY; case Noise: generationMode = DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT; break; @@ -620,7 +620,6 @@ public final class WorldGenerationStep { break; case Light: case LiquidCarvers: - case Empty: default: return; } @@ -632,10 +631,23 @@ 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) - , true); - //params.lodBuilder.generateLodNodeAsync(new ChunkWrapper(target, region), ApiShared.lodWorld, params.lodDim.dimension, - // generationMode, false, () -> {}, () -> {}); + boolean isFull = target.getStatus() == ChunkStatus.FULL || target instanceof ImposterProtoChunk; + boolean isPartial = target.isOldNoiseGeneration(); + if (isFull) { + ClientApi.LOGGER.info("Detected full existing chunk ", target.getPos()); + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), + new LodBuilderConfig(DistanceGenerationMode.FULL), true); + } else if (isPartial) { + ClientApi.LOGGER.info("Detected old existing chunk ", target.getPos()); + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), + new LodBuilderConfig(generationMode), true); + } else if (target.getStatus() == ChunkStatus.EMPTY && generationMode == DistanceGenerationMode.NONE) { + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), + LodBuilderConfig.getFillVoidConfig(), true); + } else { + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), + new LodBuilderConfig(generationMode), true); + } } } e.pEvent.endNano = System.nanoTime(); @@ -651,10 +663,9 @@ public final class WorldGenerationStep { try { subRange.forEach((chunk) -> { ((ProtoChunk) chunk).setLightEngine(region.getLightEngine()); - if (region.lightMode == LightMode.Step) { - ((WorldGenLevelLightEngine)region.getLightEngine()).lightChunk(chunk, false); - } }); + if (step == Steps.Empty) + return subRange; stepStructureStart.generateGroup(e.tParam, region, subRange); e.pEvent.structStartNano = System.nanoTime(); e.refreshTimeout(); @@ -691,14 +702,10 @@ public final class WorldGenerationStep { return subRange; } finally { switch (region.lightMode) { - case StarLight: - case Fancy: + case FANCY: stepLight.generateGroup(region.getLightEngine(), subRange); break; - case Step: - ((WorldGenLevelLightEngine)region.getLightEngine()).runUpdates(); - break; - case Fast: + case FAST: break; } e.pEvent.lightNano = System.nanoTime(); @@ -1013,11 +1020,11 @@ public final class WorldGenerationStep { public static class LightedWorldGenRegion extends WorldGenRegion { final WorldGenLevelLightEngine light; - final LightMode lightMode; + final LightGenerationMode lightMode; final EmptyChunkGenerator generator; Long2ObjectOpenHashMap chunkMap = new Long2ObjectOpenHashMap(); public LightedWorldGenRegion(ServerLevel serverLevel, List list, ChunkStatus chunkStatus, int i, - LightMode lightMode, EmptyChunkGenerator generator) { + LightGenerationMode lightMode, EmptyChunkGenerator generator) { super(serverLevel, list, chunkStatus, i); this.lightMode = lightMode; this.generator = generator; @@ -1072,7 +1079,7 @@ public final class WorldGenerationStep { @Override public int getBrightness(LightLayer lightLayer, BlockPos blockPos) { - if (lightMode != LightMode.Fast) { + if (lightMode != LightGenerationMode.FAST) { return light.getLayerListener(lightLayer).getLightValue(blockPos); } if (lightLayer == LightLayer.BLOCK) return 0; @@ -1082,7 +1089,7 @@ public final class WorldGenerationStep { @Override public int getRawBrightness(BlockPos blockPos, int i) { - if (lightMode != LightMode.Fast) { + if (lightMode != LightGenerationMode.FAST) { return light.getRawBrightness(blockPos, i); } BlockPos p = super.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, blockPos); @@ -1124,7 +1131,7 @@ public final class WorldGenerationStep { final boolean shouldReturnNull; public LightGetterAdaptor(LightedWorldGenRegion genRegion) { this.genRegion = genRegion; - shouldReturnNull = genRegion.lightMode==LightMode.StarLight ? true : false; + shouldReturnNull = ModAccessorApi.get(IStarlightAccessor.class)!=null; } @Override public BlockGetter getChunkForLighting(int chunkX, int chunkZ) { diff --git a/core b/core index bdd877abe..43feb2d7f 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit bdd877abe8bcbaca93fc7e959cf9a738d43342a1 +Subproject commit 43feb2d7fe73690c1e06560f8f0ea6f6256b827a