From 9afcddca4f9ccb61dcdfdce045d53fb6806815aa Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 7 Sep 2024 12:07:59 -0500 Subject: [PATCH] Add faster sky light engine from Builderb0y Closes !67 --- .../common/wrappers/chunk/ChunkWrapper.java | 90 ++----------------- .../BatchGenerationEnvironment.java | 13 +-- coreSubProjects | 2 +- 3 files changed, 13 insertions(+), 92 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java index 962d8a614..5f0276e43 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java @@ -94,7 +94,8 @@ public class ChunkWrapper implements IChunkWrapper private final LevelReader lightSource; private final ILevelWrapper wrappedLevel; - private boolean isDhLightCorrect = false; + private boolean isDhBlockLightCorrect = false; + private boolean isDhSkyLightCorrect = false; /** only used when connected to a dedicated server */ private boolean isMcClientLightingCorrect = false; @@ -103,8 +104,6 @@ public class ChunkWrapper implements IChunkWrapper private ArrayList blockLightPosList = null; - private boolean useDhLighting; - private int minNonEmptyHeight = Integer.MIN_VALUE; private int maxNonEmptyHeight = Integer.MAX_VALUE; @@ -136,11 +135,6 @@ public class ChunkWrapper implements IChunkWrapper this.wrappedLevel = wrappedLevel; this.chunkPos = new DhChunkPos(chunk.getPos().x, chunk.getPos().z); - // TODO is this the best way to differentiate between when we are generating chunks and when MC gave us a chunk? - boolean isDhGeneratedChunk = (this.lightSource.getClass() == DhLitWorldGenRegion.class); - // MC loaded chunks should get their lighting from MC, DH generated chunks should get their lighting from DH - this.useDhLighting = isDhGeneratedChunk; - // FIXME +1 is to handle the fact that LodDataBuilder adds +1 to all block lighting calculations, also done in the relative position validator chunksNeedingClientLightUpdating.add(this); @@ -346,45 +340,15 @@ public class ChunkWrapper implements IChunkWrapper // lighting // //==========// - @Override - public void setIsDhLightCorrect(boolean isDhLightCorrect) { this.isDhLightCorrect = isDhLightCorrect; } + @Override + public void setIsDhSkyLightCorrect(boolean isDhLightCorrect) { this.isDhSkyLightCorrect = isDhLightCorrect; } + @Override + public void setIsDhBlockLightCorrect(boolean isDhLightCorrect) { this.isDhBlockLightCorrect = isDhLightCorrect; } @Override - public void setUseDhLighting(boolean useDhLighting) { this.useDhLighting = useDhLighting; } - + public boolean isDhBlockLightingCorrect() { return this.isDhBlockLightCorrect; } @Override - public boolean isLightCorrect() - { - if (this.useDhLighting) - { - return this.isDhLightCorrect; - } - - - #if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1 - return false; // MC's lighting engine doesn't work consistently enough to trust for 1.16 or 1.17 - #else - if (this.chunk instanceof LevelChunk) - { - LevelChunk levelChunk = (LevelChunk) this.chunk; - if (levelChunk.getLevel() instanceof ClientLevel) - { - // connected to a server - return this.isMcClientLightingCorrect; - } - else - { - // in a single player world - return this.chunk.isLightCorrect() && levelChunk.loaded; - } - } - else - { - // called when in a single player world and the chunk is a proto chunk (in world gen, and not active) - return this.chunk.isLightCorrect(); - } - #endif - } + public boolean isDhSkyLightCorrect() { return this.isDhSkyLightCorrect; } @Override @@ -439,44 +403,6 @@ public class ChunkWrapper implements IChunkWrapper public void setSkyLightStorage(ChunkLightStorage lightStorage) { this.skyLightStorage = lightStorage; } - @Override - public int getBlockLight(int relX, int y, int relZ) - { - this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, y, relZ); - - // use the full lighting engine when the chunks are within render distance or the config requests it - if (this.useDhLighting) - { - // DH lighting method - return this.getBlockLightStorage().get(relX, y, relZ); - } - else - { - // note: this returns 0 if the chunk is unload - - // MC lighting method - return this.lightSource.getBrightness(LightLayer.BLOCK, new BlockPos(relX + this.getMinBlockX(), y, relZ + this.getMinBlockZ())); - } - } - - @Override - public int getSkyLight(int relX, int y, int relZ) - { - this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, y, relZ); - - // use the full lighting engine when the chunks are within render distance or the config requests it - if (this.useDhLighting) - { - // DH lighting method - return this.getSkyLightStorage().get(relX, y, relZ); - } - else - { - // MC lighting method - return this.lightSource.getBrightness(LightLayer.SKY, new BlockPos(relX + this.getMinBlockX(), y, relZ + this.getMinBlockZ())); - } - } - /** * FIXME synchronized is necessary for a rare issue where this method is called from two separate threads at the same time * before the list has finished populating. diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index 6311dfa60..e9c4ed539 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -488,8 +488,8 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv { chunkWrapper.setBlockLightStorage(chunkBlockLightingByDhPos.get(chunkWrapper.getChunkPos())); chunkWrapper.setSkyLightStorage(chunkSkyLightingByDhPos.get(chunkWrapper.getChunkPos())); - chunkWrapper.setUseDhLighting(true); - chunkWrapper.setIsDhLightCorrect(true); + chunkWrapper.setIsDhBlockLightCorrect(true); + chunkWrapper.setIsDhSkyLightCorrect(true); } chunkWrappersByDhPos.put(chunkPos, chunkWrapper); @@ -531,11 +531,6 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv #endif } - if (!wrappedChunk.isLightCorrect()) - { - throw new RuntimeException("The generated chunk somehow has isLightCorrect() returning false"); - } - boolean isFull = ChunkWrapper.getStatus(target) == ChunkStatus.FULL || target instanceof LevelChunk; #if MC_VER >= MC_1_18_2 boolean isPartial = target.isOldNoiseGeneration(); @@ -823,9 +818,9 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv Heightmap.primeHeightmaps(((ChunkWrapper)centerChunk).getChunk(), ChunkStatus.FEATURES.heightmapsAfter()); // pre-generated chunks should have lighting but new ones won't - if (!centerChunk.isLightCorrect()) + if (!centerChunk.isDhBlockLightingCorrect()) { - DhLightingEngine.INSTANCE.lightChunk(centerChunk, iChunkWrapperList, maxSkyLight); + DhLightingEngine.INSTANCE.bakeChunkBlockLighting(centerChunk, iChunkWrapperList, maxSkyLight); } } diff --git a/coreSubProjects b/coreSubProjects index 3bee25053..d96ba5ae5 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 3bee25053fda1a0887c361e0020296dbbaa671cd +Subproject commit d96ba5ae549be8b52e5752c944a4bb665f639497