diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java index 8fccf1cd7..ac2e674b1 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java @@ -9,10 +9,8 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrappe import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper; import org.apache.logging.log4j.Logger; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; /** * This logic was roughly based on @@ -43,8 +41,13 @@ public class DhLightingEngine DhChunkPos centerChunkPos = centerChunk.getChunkPos(); HashMap chunksByChunkPos = new HashMap<>(9); - LinkedList blockLightPosQueue = new LinkedList<>(); - LinkedList skyLightPosQueue = new LinkedList<>(); + + // from some quick testing on James' part, + // these initial capacities should be big enough to fit most lighting jobs + // with a bit of room to spare + ArrayList blockLightPosQueue = new ArrayList<>(40_000); // when tested with a normal 1.20 world James saw a max of: 36_709 + ArrayList skyLightPosQueue = new ArrayList<>(3_000); // when tested with a normal 1.20 world James saw a max of: 2355 + // generate the list of chunk pos we need, // currently a 3x3 grid @@ -144,16 +147,21 @@ public class DhLightingEngine /** Applies each {@link LightPos} from the queue to the given set of {@link IChunkWrapper}'s. */ private void propagateLightPosList( - LinkedList lightPosQueue, HashMap chunksByChunkPos, + ArrayList lightPosQueue, HashMap chunksByChunkPos, IGetLightFunc getLightFunc, ISetLightFunc setLightFunc) { // update each light position while (!lightPosQueue.isEmpty()) { - LightPos lightPos = lightPosQueue.poll(); + // since we don't care about the order the positions are processed, + // we can grab the last position instead of the first for a slight performance increase (this way the array doesn't need to be shifted over every loop) + int lastIndex = lightPosQueue.size() - 1; + LightPos lightPos = lightPosQueue.remove(lastIndex); + DhBlockPos pos = lightPos.pos; int lightValue = lightPos.lightValue; + // propagate the lighting in each cardinal direction, IE: -x, +x, -y, +y, -z, +z for (EDhDirection direction : EDhDirection.CARDINAL_DIRECTIONS) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/pos/DhSectionPos.java b/core/src/main/java/com/seibel/distanthorizons/core/pos/DhSectionPos.java index 8a2f94085..2edf44678 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/pos/DhSectionPos.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/pos/DhSectionPos.java @@ -46,6 +46,10 @@ public class DhSectionPos + //==============// + // constructors // + //==============// + public DhSectionPos(byte sectionDetailLevel, int sectionX, int sectionZ) { this.sectionDetailLevel = sectionDetailLevel;