diff --git a/server/src/main/java/org/allaymc/server/world/service/AllayLightService.java b/server/src/main/java/org/allaymc/server/world/service/AllayLightService.java index 2441a295f..fc0c13cd4 100644 --- a/server/src/main/java/org/allaymc/server/world/service/AllayLightService.java +++ b/server/src/main/java/org/allaymc/server/world/service/AllayLightService.java @@ -2,8 +2,6 @@ import com.google.common.base.Preconditions; import io.netty.util.internal.PlatformDependent; -import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongSet; import org.allaymc.api.block.data.BlockFace; @@ -16,6 +14,7 @@ import org.allaymc.api.world.chunk.Chunk; import org.allaymc.api.world.service.LightService; import org.allaymc.server.datastruct.ChunkSectionNibbleArray; +import org.allaymc.server.datastruct.collections.nb.Long2ObjectNonBlockingMap; import org.allaymc.server.datastruct.collections.queue.BlockingQueueWrapper; import org.allaymc.server.world.HeightMap; import org.allaymc.server.world.chunk.AllayUnsafeChunk; @@ -41,11 +40,11 @@ public class AllayLightService implements LightService { // TODO(memory): use a more memory-efficient queue, for example a long queue protected final BlockingQueueWrapper queue; protected final LongSet chunks; - protected final Long2ObjectMap lightDampening; - protected final Long2ObjectMap blockLight; + protected final Long2ObjectNonBlockingMap lightDampening; + protected final Long2ObjectNonBlockingMap blockLight; protected final LightPropagator blockLightPropagator; - protected Long2ObjectMap lightHeightMap; - protected Long2ObjectMap skyLight; + protected Long2ObjectNonBlockingMap lightHeightMap; + protected Long2ObjectNonBlockingMap skyLight; protected LightPropagator skyLightPropagator; public AllayLightService(Dimension dimension) { @@ -62,12 +61,12 @@ public AllayLightService(DimensionInfo dimensionInfo, Supplier timeSupp this.hasSkyLight = dimensionInfo.hasSkyLight(); this.queue = BlockingQueueWrapper.wrap(PlatformDependent.newMpscQueue()); this.chunks = new LongOpenHashSet(); - this.lightDampening = new Long2ObjectOpenHashMap<>(); - this.blockLight = new Long2ObjectOpenHashMap<>(); + this.lightDampening = new Long2ObjectNonBlockingMap<>(); + this.blockLight = new Long2ObjectNonBlockingMap<>(); this.blockLightPropagator = new LightPropagator(new BlockLightAccessor()); if (hasSkyLight) { - this.lightHeightMap = new Long2ObjectOpenHashMap<>(); - this.skyLight = new Long2ObjectOpenHashMap<>(); + this.lightHeightMap = new Long2ObjectNonBlockingMap<>(); + this.skyLight = new Long2ObjectNonBlockingMap<>(); this.skyLightPropagator = new LightPropagator(new SkyLightAccessor()); } } @@ -275,13 +274,13 @@ protected int getLightDampening(int x, int y, int z) { return get(lightDampening, x, y, z, 0); } - protected int getWithoutCheck(Long2ObjectMap target, int x, int y, int z) { + protected int getWithoutCheck(Long2ObjectNonBlockingMap target, int x, int y, int z) { var hash = HashUtils.hashXZ(x >> 4, z >> 4); var array = target.get(hash); return array[(y - minHeight) >> 4].get(x & 15, y & 15, z & 15); } - protected int get(Long2ObjectMap target, int x, int y, int z, int defaultValue) { + protected int get(Long2ObjectNonBlockingMap target, int x, int y, int z, int defaultValue) { var hash = HashUtils.hashXZ(x >> 4, z >> 4); if (!chunks.contains(hash)) { return defaultValue; @@ -313,7 +312,7 @@ protected void setLightDampening(int x, int y, int z, int value) { } } - protected void set(Long2ObjectMap target, int x, int y, int z, int value) { + protected void set(Long2ObjectNonBlockingMap target, int x, int y, int z, int value) { var hash = HashUtils.hashXZ(x >> 4, z >> 4); if (!chunks.contains(hash)) { return; @@ -322,7 +321,7 @@ protected void set(Long2ObjectMap target, int x, int array[(y - minHeight) >> 4].set(x & 15, y & 15, z & 15, value); } - protected void setWithoutCheck(Long2ObjectMap target, int x, int y, int z, int value) { + protected void setWithoutCheck(Long2ObjectNonBlockingMap target, int x, int y, int z, int value) { var hash = HashUtils.hashXZ(x >> 4, z >> 4); var array = target.get(hash); array[(y - minHeight) >> 4].set(x & 15, y & 15, z & 15, value);