Optimize DH lighting for chunks with populated sections

Specifically improves lighting speed for BigGlobe worlds
This commit is contained in:
James Seibel
2023-12-14 07:50:23 -06:00
parent 77d8f413e6
commit ebebc5566e
3 changed files with 14 additions and 8 deletions
@@ -48,7 +48,7 @@ public class LodDataBuilder
ChunkSizedFullDataAccessor chunkData = new ChunkSizedFullDataAccessor(chunkWrapper.getChunkPos());
int minBuildHeight = chunkWrapper.getMinFilledHeight();
int minBuildHeight = chunkWrapper.getMinNonEmptyHeight();
for (int x = 0; x < LodUtil.CHUNK_WIDTH; x++)
{
@@ -140,13 +140,16 @@ public class DhLightingEngine
// if the dimension has skylights
if (maxSkyLight > 0)
{
int maxY = chunk.getMaxNonEmptyHeight();
int minY = chunk.getMinBuildHeight();
// get the adjacent chunk's sky lights
for (int relX = 0; relX < LodUtil.CHUNK_WIDTH; relX++) // relative block pos
{
for (int relZ = 0; relZ < LodUtil.CHUNK_WIDTH; relZ++)
{
// set each pos' sky light all the way down until a opaque block is hit
for (int y = chunk.getMaxBuildHeight(); y >= chunk.getMinBuildHeight(); y--)
for (int y = maxY; y >= minY; y--)
{
IBlockStateWrapper block = chunk.getBlockState(relX, y, relZ);
if (block != null && block.getOpacity() != IBlockStateWrapper.FULLY_TRANSPARENT)
@@ -244,7 +247,7 @@ public class DhLightingEngine
continue;
}
if (relNeighbourBlockPos.y < neighbourChunk.getMinFilledHeight() || relNeighbourBlockPos.y > neighbourChunk.getMaxBuildHeight())
if (relNeighbourBlockPos.y < neighbourChunk.getMinNonEmptyHeight() || relNeighbourBlockPos.y > neighbourChunk.getMaxBuildHeight())
{
// the light pos is outside the chunk's min/max height,
// this can happen if given a chunk that hasn't finished generating
@@ -19,7 +19,6 @@
package com.seibel.distanthorizons.core.wrapperInterfaces.chunk;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
@@ -29,7 +28,6 @@ import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
import java.util.ArrayList;
import java.util.List;
public interface IChunkWrapper extends IBindable
{
@@ -40,10 +38,15 @@ public interface IChunkWrapper extends IBindable
int getMaxBuildHeight();
/**
* returns the Y level for the first non-empty section in this chunk,
* or {@link Integer#MAX_VALUE} if this chunk is completely empty.
* returns the Y level for the last non-empty section in this chunk,
* or {@link IChunkWrapper#getMinBuildHeight()} if this chunk is completely empty.
*/
int getMinFilledHeight();
int getMinNonEmptyHeight();
/**
* returns the Y level for the first non-empty section in this chunk,
* or {@link IChunkWrapper#getMaxBuildHeight()} if this chunk is completely empty.
*/
int getMaxNonEmptyHeight();
/** @return The highest y position of a solid block at the given relative chunk position. */
int getSolidHeightMapValue(int xRel, int zRel);