|
|
@ -5,25 +5,23 @@ Subject: [PATCH] Stop copy-on-write operations for updating light data
|
|
|
|
|
|
|
|
|
|
|
|
Causes huge memory allocations + gc issues
|
|
|
|
Causes huge memory allocations + gc issues
|
|
|
|
|
|
|
|
|
|
|
|
1.17 update note: Needs updating, temp skipped
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/lighting/BlockLightSectionStorage.java b/src/main/java/net/minecraft/world/level/lighting/BlockLightSectionStorage.java
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/lighting/BlockLightSectionStorage.java b/src/main/java/net/minecraft/world/level/lighting/BlockLightSectionStorage.java
|
|
|
|
index 9f33fa8f84d10f8f4089030074ad6c0d81269ce8..a1ad4d73ddaf6afe97a1f1ff7e0622b52fac8761 100644
|
|
|
|
index 573cdb0897978eef8f5fc906ed4928293f4b2ab9..314b46f0becd088d26956b45981217b128d539cb 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/lighting/BlockLightSectionStorage.java
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/lighting/BlockLightSectionStorage.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/lighting/BlockLightSectionStorage.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/lighting/BlockLightSectionStorage.java
|
|
|
|
@@ -10,7 +10,7 @@ import net.minecraft.world.level.chunk.LightChunkGetter;
|
|
|
|
@@ -9,7 +9,7 @@ import net.minecraft.world.level.chunk.LightChunkGetter;
|
|
|
|
public class BlockLightSectionStorage extends LayerLightSectionStorage<BlockLightSectionStorage.BlockDataLayerStorageMap> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class BlockLightSectionStorage extends LayerLightSectionStorage<BlockLightSectionStorage.BlockDataLayerStorageMap> {
|
|
|
|
protected BlockLightSectionStorage(LightChunkGetter chunkProvider) {
|
|
|
|
protected BlockLightSectionStorage(LightChunkGetter chunkProvider) {
|
|
|
|
- super(LightLayer.BLOCK, chunkProvider, new BlockLightSectionStorage.BlockDataLayerStorageMap(new Long2ObjectOpenHashMap()));
|
|
|
|
- super(LightLayer.BLOCK, chunkProvider, new BlockLightSectionStorage.BlockDataLayerStorageMap(new Long2ObjectOpenHashMap<>()));
|
|
|
|
+ super(LightLayer.BLOCK, chunkProvider, new BlockLightSectionStorage.BlockDataLayerStorageMap(new com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<>(), false)); // Paper - avoid copying light data
|
|
|
|
+ super(LightLayer.BLOCK, chunkProvider, new BlockLightSectionStorage.BlockDataLayerStorageMap(new com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<>(), false)); // Paper - avoid copying light data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@@ -23,13 +23,13 @@ public class BlockLightSectionStorage extends LayerLightSectionStorage<BlockLigh
|
|
|
|
@@ -20,13 +20,13 @@ public class BlockLightSectionStorage extends LayerLightSectionStorage<BlockLigh
|
|
|
|
|
|
|
|
}
|
|
|
|
public static final class BlockDataLayerStorageMap extends DataLayerStorageMap<BlockLightSectionStorage.BlockDataLayerStorageMap> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected static final class BlockDataLayerStorageMap extends DataLayerStorageMap<BlockLightSectionStorage.BlockDataLayerStorageMap> {
|
|
|
|
- public BlockDataLayerStorageMap(Long2ObjectOpenHashMap<DataLayer> arrays) {
|
|
|
|
- public BlockDataLayerStorageMap(Long2ObjectOpenHashMap<DataLayer> arrays) {
|
|
|
|
- super(arrays);
|
|
|
|
- super(arrays);
|
|
|
|
+ public BlockDataLayerStorageMap(com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<DataLayer> long2objectopenhashmap, boolean isVisible) { // Paper - avoid copying light data
|
|
|
|
+ public BlockDataLayerStorageMap(com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<DataLayer> long2objectopenhashmap, boolean isVisible) { // Paper - avoid copying light data
|
|
|
@ -38,7 +36,7 @@ index 9f33fa8f84d10f8f4089030074ad6c0d81269ce8..a1ad4d73ddaf6afe97a1f1ff7e0622b5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/lighting/DataLayerStorageMap.java b/src/main/java/net/minecraft/world/level/lighting/DataLayerStorageMap.java
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/lighting/DataLayerStorageMap.java b/src/main/java/net/minecraft/world/level/lighting/DataLayerStorageMap.java
|
|
|
|
index 01ae1c811862f56317a90e3811fe2ef4b593695f..4c9041f1c1cb4b3ec114fbd0c5d4db50a6f2526d 100644
|
|
|
|
index 67ff66e232592203cf8dad605ad01eabc4dded89..f357a3473682c2d37a20fb862522c67b9979402a 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/lighting/DataLayerStorageMap.java
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/lighting/DataLayerStorageMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/lighting/DataLayerStorageMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/lighting/DataLayerStorageMap.java
|
|
|
|
@@ -9,10 +9,23 @@ public abstract class DataLayerStorageMap<M extends DataLayerStorageMap<M>> {
|
|
|
|
@@ -9,10 +9,23 @@ public abstract class DataLayerStorageMap<M extends DataLayerStorageMap<M>> {
|
|
|
@ -46,13 +44,12 @@ index 01ae1c811862f56317a90e3811fe2ef4b593695f..4c9041f1c1cb4b3ec114fbd0c5d4db50
|
|
|
|
private final DataLayer[] lastSections = new DataLayer[2];
|
|
|
|
private final DataLayer[] lastSections = new DataLayer[2];
|
|
|
|
private boolean cacheEnabled;
|
|
|
|
private boolean cacheEnabled;
|
|
|
|
- protected final Long2ObjectOpenHashMap<DataLayer> map;
|
|
|
|
- protected final Long2ObjectOpenHashMap<DataLayer> map;
|
|
|
|
-
|
|
|
|
|
|
|
|
- protected DataLayerStorageMap(Long2ObjectOpenHashMap<DataLayer> arrays) {
|
|
|
|
|
|
|
|
- this.map = arrays;
|
|
|
|
|
|
|
|
+ protected final com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<DataLayer> data; // Paper - avoid copying light data
|
|
|
|
+ protected final com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<DataLayer> data; // Paper - avoid copying light data
|
|
|
|
+ protected final boolean isVisible; // Paper - avoid copying light data
|
|
|
|
+ protected final boolean isVisible; // Paper - avoid copying light data
|
|
|
|
+ java.util.function.Function<Long, DataLayer> lookup; // Paper - faster branchless lookup
|
|
|
|
+ java.util.function.Function<Long, DataLayer> lookup; // Paper - faster branchless lookup
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
- protected DataLayerStorageMap(Long2ObjectOpenHashMap<DataLayer> arrays) {
|
|
|
|
|
|
|
|
- this.map = arrays;
|
|
|
|
+ // Paper start - avoid copying light data
|
|
|
|
+ // Paper start - avoid copying light data
|
|
|
|
+ protected DataLayerStorageMap(com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<DataLayer> data, boolean isVisible) {
|
|
|
|
+ protected DataLayerStorageMap(com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<DataLayer> data, boolean isVisible) {
|
|
|
|
+ if (isVisible) {
|
|
|
|
+ if (isVisible) {
|
|
|
@ -73,7 +70,7 @@ index 01ae1c811862f56317a90e3811fe2ef4b593695f..4c9041f1c1cb4b3ec114fbd0c5d4db50
|
|
|
|
public abstract M copy();
|
|
|
|
public abstract M copy();
|
|
|
|
|
|
|
|
|
|
|
|
public void copyDataLayer(long pos) {
|
|
|
|
public void copyDataLayer(long pos) {
|
|
|
|
- this.map.put(pos, ((DataLayer) this.map.get(pos)).copy());
|
|
|
|
- this.map.put(pos, this.map.get(pos).copy());
|
|
|
|
+ if (this.isVisible) { throw new IllegalStateException("writing to visible data"); } // Paper - avoid copying light data
|
|
|
|
+ if (this.isVisible) { throw new IllegalStateException("writing to visible data"); } // Paper - avoid copying light data
|
|
|
|
+ this.data.queueUpdate(pos, ((DataLayer) this.data.getUpdating(pos)).copy()); // Paper - avoid copying light data
|
|
|
|
+ this.data.queueUpdate(pos, ((DataLayer) this.data.getUpdating(pos)).copy()); // Paper - avoid copying light data
|
|
|
|
this.clearCache();
|
|
|
|
this.clearCache();
|
|
|
@ -88,22 +85,22 @@ index 01ae1c811862f56317a90e3811fe2ef4b593695f..4c9041f1c1cb4b3ec114fbd0c5d4db50
|
|
|
|
- public DataLayer getLayer(long chunkPos) {
|
|
|
|
- public DataLayer getLayer(long chunkPos) {
|
|
|
|
+ public final DataLayer getLayer(long chunkPos) { // Paper - final
|
|
|
|
+ public final DataLayer getLayer(long chunkPos) { // Paper - final
|
|
|
|
if (this.cacheEnabled) {
|
|
|
|
if (this.cacheEnabled) {
|
|
|
|
for (int j = 0; j < 2; ++j) {
|
|
|
|
for(int i = 0; i < 2; ++i) {
|
|
|
|
if (chunkPos == this.lastSectionKeys[j]) {
|
|
|
|
if (chunkPos == this.lastSectionKeys[i]) {
|
|
|
|
@@ -38,7 +52,7 @@ public abstract class DataLayerStorageMap<M extends DataLayerStorageMap<M>> {
|
|
|
|
@@ -38,7 +52,7 @@ public abstract class DataLayerStorageMap<M extends DataLayerStorageMap<M>> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- DataLayer nibblearray = (DataLayer) this.map.get(chunkPos);
|
|
|
|
- DataLayer dataLayer = this.map.get(chunkPos);
|
|
|
|
+ DataLayer nibblearray = lookup.apply(chunkPos); // Paper - avoid copying light data
|
|
|
|
+ DataLayer dataLayer = lookup.apply(chunkPos); // Paper - avoid copying light data
|
|
|
|
|
|
|
|
if (dataLayer == null) {
|
|
|
|
if (nibblearray == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
@@ -59,11 +73,13 @@ public abstract class DataLayerStorageMap<M extends DataLayerStorageMap<M>> {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
@@ -58,11 +72,13 @@ public abstract class DataLayerStorageMap<M extends DataLayerStorageMap<M>> {
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Nullable
|
|
|
|
public DataLayer removeLayer(long chunkPos) {
|
|
|
|
public DataLayer removeLayer(long chunkPos) {
|
|
|
|
- return (DataLayer) this.map.remove(chunkPos);
|
|
|
|
- return this.map.remove(chunkPos);
|
|
|
|
+ if (this.isVisible) { throw new IllegalStateException("writing to visible data"); } // Paper - avoid copying light data
|
|
|
|
+ if (this.isVisible) { throw new IllegalStateException("writing to visible data"); } // Paper - avoid copying light data
|
|
|
|
+ return (DataLayer) this.data.queueRemove(chunkPos); // Paper - avoid copying light data
|
|
|
|
+ return (DataLayer) this.data.queueRemove(chunkPos); // Paper - avoid copying light data
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -115,45 +112,35 @@ index 01ae1c811862f56317a90e3811fe2ef4b593695f..4c9041f1c1cb4b3ec114fbd0c5d4db50
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void clearCache() {
|
|
|
|
public void clearCache() {
|
|
|
|
@@ -71,7 +87,6 @@ public abstract class DataLayerStorageMap<M extends DataLayerStorageMap<M>> {
|
|
|
|
|
|
|
|
this.lastSectionKeys[i] = Long.MAX_VALUE;
|
|
|
|
|
|
|
|
this.lastSections[i] = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void disableCache() {
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/lighting/LayerLightSectionStorage.java b/src/main/java/net/minecraft/world/level/lighting/LayerLightSectionStorage.java
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/lighting/LayerLightSectionStorage.java b/src/main/java/net/minecraft/world/level/lighting/LayerLightSectionStorage.java
|
|
|
|
index 45be10a0d7c26e4b6e5738ba994ce343265210f5..177dae992d13674bb285a60b8427df9ea843dc99 100644
|
|
|
|
index ee32aba07aad4a3f101a6a57f7aa6c07f74dd0c3..cc9eb8273d5157fb649d84a3ec589b0b923b5bc9 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/lighting/LayerLightSectionStorage.java
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/lighting/LayerLightSectionStorage.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/lighting/LayerLightSectionStorage.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/lighting/LayerLightSectionStorage.java
|
|
|
|
@@ -26,8 +26,8 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
|
|
|
|
@@ -28,7 +28,7 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
|
|
|
|
protected final LongSet dataSectionSet = new LongOpenHashSet();
|
|
|
|
protected final LongSet dataSectionSet = new LongOpenHashSet();
|
|
|
|
protected final LongSet toMarkNoData = new LongOpenHashSet();
|
|
|
|
protected final LongSet toMarkNoData = new LongOpenHashSet();
|
|
|
|
protected final LongSet toMarkData = new LongOpenHashSet();
|
|
|
|
protected final LongSet toMarkData = new LongOpenHashSet();
|
|
|
|
- protected volatile M visibleSectionData;
|
|
|
|
- protected volatile M visibleSectionData;
|
|
|
|
- protected final M updatingSectionData;
|
|
|
|
|
|
|
|
+ protected volatile M e_visible; protected final Object visibleUpdateLock = new Object(); // Paper - diff on change, should be "visible" - force compile fail on usage change
|
|
|
|
+ protected volatile M e_visible; protected final Object visibleUpdateLock = new Object(); // Paper - diff on change, should be "visible" - force compile fail on usage change
|
|
|
|
+ protected final M updatingSectionData; // Paper - diff on change, should be "updating"
|
|
|
|
protected final M updatingSectionData;
|
|
|
|
protected final LongSet changedSections = new LongOpenHashSet();
|
|
|
|
protected final LongSet changedSections = new LongOpenHashSet();
|
|
|
|
protected final LongSet sectionsAffectedByLightUpdates = new LongOpenHashSet();
|
|
|
|
protected final LongSet sectionsAffectedByLightUpdates = new LongOpenHashSet();
|
|
|
|
protected final Long2ObjectMap<DataLayer> queuedSections = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap());
|
|
|
|
@@ -43,8 +43,8 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
|
|
|
|
@@ -41,8 +41,8 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
|
|
|
|
|
|
|
|
this.layer = lightType;
|
|
|
|
this.layer = lightType;
|
|
|
|
this.chunkSource = chunkProvider;
|
|
|
|
this.chunkSource = chunkProvider;
|
|
|
|
this.updatingSectionData = lightData;
|
|
|
|
this.updatingSectionData = lightData;
|
|
|
|
- this.visibleSectionData = lightData.copy();
|
|
|
|
- this.visibleSectionData = lightData.copy();
|
|
|
|
- this.visibleSectionData.disableCache();
|
|
|
|
- this.visibleSectionData.disableCache();
|
|
|
|
+ this.e_visible = lightData.copy(); // Paper - avoid copying light data
|
|
|
|
+ this.e_visible = lightData.copy(); // Paper - avoid copying light dat
|
|
|
|
+ this.e_visible.disableCache(); // Paper - avoid copying light data
|
|
|
|
+ this.e_visible.disableCache(); // Paper - avoid copying light dat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected boolean storingLightForSection(long sectionPos) {
|
|
|
|
protected boolean storingLightForSection(long sectionPos) {
|
|
|
|
@@ -51,7 +51,15 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
|
|
|
|
@@ -53,7 +53,15 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Nullable
|
|
|
|
protected DataLayer getDataLayer(long sectionPos, boolean cached) {
|
|
|
|
protected DataLayer getDataLayer(long sectionPos, boolean cached) {
|
|
|
|
- return this.getDataLayer(cached ? this.updatingSectionData : this.visibleSectionData, sectionPos);
|
|
|
|
- return this.getDataLayer((M)(cached ? this.updatingSectionData : this.visibleSectionData), sectionPos);
|
|
|
|
+ // Paper start - avoid copying light data
|
|
|
|
+ // Paper start - avoid copying light data
|
|
|
|
+ if (cached) {
|
|
|
|
+ if (cached) {
|
|
|
|
+ return this.getDataLayer(this.updatingSectionData, sectionPos);
|
|
|
|
+ return this.getDataLayer(this.updatingSectionData, sectionPos);
|
|
|
@ -166,150 +153,138 @@ index 45be10a0d7c26e4b6e5738ba994ce343265210f5..177dae992d13674bb285a60b8427df9e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Nullable
|
|
|
|
@@ -364,10 +372,12 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
|
|
|
|
@@ -346,9 +354,11 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
|
|
|
|
|
|
|
|
|
|
|
|
protected void swapSectionMap() {
|
|
|
|
protected void swapSectionMap() {
|
|
|
|
if (!this.changedSections.isEmpty()) {
|
|
|
|
if (!this.changedSections.isEmpty()) {
|
|
|
|
+ synchronized (this.visibleUpdateLock) { // Paper - avoid copying light data
|
|
|
|
+ synchronized (this.visibleUpdateLock) { // Paper - avoid copying light data
|
|
|
|
M m0 = this.updatingSectionData.copy();
|
|
|
|
M dataLayerStorageMap = this.updatingSectionData.copy();
|
|
|
|
|
|
|
|
dataLayerStorageMap.disableCache();
|
|
|
|
m0.disableCache();
|
|
|
|
- this.visibleSectionData = dataLayerStorageMap;
|
|
|
|
- this.visibleSectionData = m0;
|
|
|
|
+ this.e_visible = dataLayerStorageMap; // Paper - avoid copying light data
|
|
|
|
+ this.e_visible = m0; // Paper - avoid copying light data
|
|
|
|
|
|
|
|
+ } // Paper - avoid copying light data
|
|
|
|
+ } // Paper - avoid copying light data
|
|
|
|
this.changedSections.clear();
|
|
|
|
this.changedSections.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/lighting/SkyLightSectionStorage.java b/src/main/java/net/minecraft/world/level/lighting/SkyLightSectionStorage.java
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/lighting/SkyLightSectionStorage.java b/src/main/java/net/minecraft/world/level/lighting/SkyLightSectionStorage.java
|
|
|
|
index c304637ae8f80c65b58e8ba8a27609b532bb1184..410fcfa8c01b7e3d3e3829ebdb92a11badff16ea 100644
|
|
|
|
index fb41fddaee27097b8b503ae13d6a775b207f883a..f6df52403a1068a0779e4ff8c2ce5dc06176e061 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/lighting/SkyLightSectionStorage.java
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/lighting/SkyLightSectionStorage.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/lighting/SkyLightSectionStorage.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/lighting/SkyLightSectionStorage.java
|
|
|
|
@@ -23,15 +23,16 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
@@ -21,7 +21,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
private volatile boolean hasSourceInconsistencies;
|
|
|
|
private volatile boolean hasSourceInconsistencies;
|
|
|
|
|
|
|
|
|
|
|
|
protected SkyLightSectionStorage(LightChunkGetter chunkProvider) {
|
|
|
|
protected SkyLightSectionStorage(LightChunkGetter chunkProvider) {
|
|
|
|
- super(LightLayer.SKY, chunkProvider, new SkyLightSectionStorage.SkyDataLayerStorageMap(new Long2ObjectOpenHashMap(), new Long2IntOpenHashMap(), Integer.MAX_VALUE));
|
|
|
|
- super(LightLayer.SKY, chunkProvider, new SkyLightSectionStorage.SkyDataLayerStorageMap(new Long2ObjectOpenHashMap<>(), new Long2IntOpenHashMap(), Integer.MAX_VALUE));
|
|
|
|
+ super(LightLayer.SKY, chunkProvider, new SkyLightSectionStorage.SkyDataLayerStorageMap(new com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<>(), new com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int(), Integer.MAX_VALUE, false)); // Paper - avoid copying light data
|
|
|
|
+ super(LightLayer.SKY, chunkProvider, new SkyLightSectionStorage.SkyDataLayerStorageMap(new com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<>(), new com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int(), Integer.MAX_VALUE, false)); // Paper - avoid copying light data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected int getLightValue(long blockPos) {
|
|
|
|
@@ -32,8 +32,9 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
long j = SectionPos.blockToSection(blockPos);
|
|
|
|
protected int getLightValue(long l, boolean bl) {
|
|
|
|
int k = SectionPos.y(j);
|
|
|
|
long m = SectionPos.blockToSection(l);
|
|
|
|
- SkyLightSectionStorage.SkyDataLayerStorageMap lightenginestoragesky_a = (SkyLightSectionStorage.SkyDataLayerStorageMap) this.visibleSectionData;
|
|
|
|
int i = SectionPos.y(m);
|
|
|
|
- int l = lightenginestoragesky_a.topSections.get(SectionPos.getZeroNode(j));
|
|
|
|
- SkyLightSectionStorage.SkyDataLayerStorageMap skyDataLayerStorageMap = bl ? this.updatingSectionData : this.visibleSectionData;
|
|
|
|
|
|
|
|
- int j = skyDataLayerStorageMap.topSections.get(SectionPos.getZeroNode(m));
|
|
|
|
+ synchronized (this.visibleUpdateLock) { // Paper - avoid copying light data
|
|
|
|
+ synchronized (this.visibleUpdateLock) { // Paper - avoid copying light data
|
|
|
|
+ SkyLightSectionStorage.SkyDataLayerStorageMap lightenginestoragesky_a = (SkyLightSectionStorage.SkyDataLayerStorageMap) this.e_visible; // Paper - avoid copying light data - must be after lock acquire
|
|
|
|
+ SkyLightSectionStorage.SkyDataLayerStorageMap skyDataLayerStorageMap = (SkyLightSectionStorage.SkyDataLayerStorageMap) this.e_visible; // Paper - avoid copying light data - must be after lock acquire
|
|
|
|
+ int l = lightenginestoragesky_a.otherData.getVisibleAsync(SectionPos.getZeroNode(j)); // Paper - avoid copying light data
|
|
|
|
+ int j = skyDataLayerStorageMap.otherData.getVisibleAsync(SectionPos.getZeroNode(m)); // Paper - avoid copying light data
|
|
|
|
|
|
|
|
if (j != skyDataLayerStorageMap.currentLowestY && i < j) {
|
|
|
|
if (l != lightenginestoragesky_a.currentLowestY && k < l) {
|
|
|
|
DataLayer dataLayer = this.getDataLayer(skyDataLayerStorageMap, m);
|
|
|
|
DataLayer nibblearray = this.getDataLayer(lightenginestoragesky_a, j); // Paper - decompile fix
|
|
|
|
if (dataLayer == null) {
|
|
|
|
@@ -52,6 +53,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
@@ -52,6 +53,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return 15;
|
|
|
|
return bl && !this.lightOnInSection(m) ? 0 : 15;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ } // Paper - avoid copying light data
|
|
|
|
+ } // Paper - avoid copying light data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@@ -60,14 +62,14 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
@@ -59,13 +61,13 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
|
|
|
|
int i = SectionPos.y(sectionPos);
|
|
|
|
if (((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY > j) {
|
|
|
|
if ((this.updatingSectionData).currentLowestY > i) {
|
|
|
|
((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY = j;
|
|
|
|
(this.updatingSectionData).currentLowestY = i;
|
|
|
|
- ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.defaultReturnValue(((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY);
|
|
|
|
- (this.updatingSectionData).topSections.defaultReturnValue((this.updatingSectionData).currentLowestY);
|
|
|
|
+ ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.queueDefaultReturnValue(((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY); // Paper - avoid copying light data
|
|
|
|
+ (this.updatingSectionData).otherData.queueDefaultReturnValue((this.updatingSectionData).currentLowestY); // Paper - avoid copying light data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long k = SectionPos.getZeroNode(sectionPos);
|
|
|
|
long l = SectionPos.getZeroNode(sectionPos);
|
|
|
|
- int l = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.get(k);
|
|
|
|
- int j = (this.updatingSectionData).topSections.get(l);
|
|
|
|
+ int l = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.getUpdating(k); // Paper - avoid copying light data
|
|
|
|
+ int j = (this.updatingSectionData).otherData.getUpdating(l); // Paper - avoid copying light data
|
|
|
|
|
|
|
|
if (j < i + 1) {
|
|
|
|
if (l < j + 1) {
|
|
|
|
- (this.updatingSectionData).topSections.put(l, i + 1);
|
|
|
|
- ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.put(k, j + 1);
|
|
|
|
+ (this.updatingSectionData).otherData.queueUpdate(l, i + 1); // Paper - avoid copying light data
|
|
|
|
+ ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.queueUpdate(k, j + 1); // Paper - avoid copying light data
|
|
|
|
if (this.columnsWithSkySources.contains(l)) {
|
|
|
|
if (this.columnsWithSkySources.contains(k)) {
|
|
|
|
|
|
|
|
this.queueAddSource(sectionPos);
|
|
|
|
this.queueAddSource(sectionPos);
|
|
|
|
if (l > ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY) {
|
|
|
|
if (j > (this.updatingSectionData).currentLowestY) {
|
|
|
|
@@ -107,7 +109,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
@@ -102,19 +104,19 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int k = SectionPos.y(sectionPos);
|
|
|
|
int i = SectionPos.y(sectionPos);
|
|
|
|
|
|
|
|
- if ((this.updatingSectionData).topSections.get(l) == i + 1) {
|
|
|
|
- if (((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.get(j) == k + 1) {
|
|
|
|
+ if ((this.updatingSectionData).otherData.getUpdating(l) == i + 1) { // Paper - avoid copying light data
|
|
|
|
+ if (((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.getUpdating(j) == k + 1) { // Paper - avoid copying light data
|
|
|
|
long m;
|
|
|
|
long l;
|
|
|
|
for(m = sectionPos; !this.storingLightForSection(m) && this.hasSectionsBelow(i); m = SectionPos.offset(m, Direction.DOWN)) {
|
|
|
|
|
|
|
|
--i;
|
|
|
|
for (l = sectionPos; !this.storingLightForSection(l) && this.hasSectionsBelow(k); l = SectionPos.offset(l, Direction.DOWN)) {
|
|
|
|
|
|
|
|
@@ -115,12 +117,12 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.storingLightForSection(l)) {
|
|
|
|
if (this.storingLightForSection(m)) {
|
|
|
|
- ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.put(j, k + 1);
|
|
|
|
- (this.updatingSectionData).topSections.put(l, i + 1);
|
|
|
|
+ ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.queueUpdate(j, k + 1); // Paper - avoid copying light data
|
|
|
|
+ (this.updatingSectionData).otherData.queueUpdate(l, i + 1); // Paper - avoid copying light data
|
|
|
|
if (flag) {
|
|
|
|
if (bl) {
|
|
|
|
this.queueAddSource(l);
|
|
|
|
this.queueAddSource(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
- ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.remove(j);
|
|
|
|
- (this.updatingSectionData).topSections.remove(l);
|
|
|
|
+ ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.queueRemove(j); // Paper - avoid copying light data
|
|
|
|
+ (this.updatingSectionData).otherData.queueRemove(l); // Paper - avoid copying light data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -134,7 +136,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
@@ -128,7 +130,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
protected void enableLightSources(long columnPos, boolean enabled) {
|
|
|
|
protected void enableLightSources(long columnPos, boolean enabled) {
|
|
|
|
this.runAllUpdates();
|
|
|
|
this.runAllUpdates();
|
|
|
|
if (enabled && this.columnsWithSkySources.add(columnPos)) {
|
|
|
|
if (enabled && this.columnsWithSkySources.add(columnPos)) {
|
|
|
|
- int j = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.get(columnPos);
|
|
|
|
- int i = (this.updatingSectionData).topSections.get(columnPos);
|
|
|
|
+ int j = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.getUpdating(columnPos); // Paper - avoid copying light data
|
|
|
|
+ int i = (this.updatingSectionData).otherData.getUpdating(columnPos); // Paper - avoid copying light data
|
|
|
|
|
|
|
|
if (i != (this.updatingSectionData).currentLowestY) {
|
|
|
|
if (j != ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY) {
|
|
|
|
long l = SectionPos.asLong(SectionPos.x(columnPos), i - 1, SectionPos.z(columnPos));
|
|
|
|
long k = SectionPos.asLong(SectionPos.x(columnPos), j - 1, SectionPos.z(columnPos));
|
|
|
|
this.queueAddSource(l);
|
|
|
|
@@ -161,7 +163,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
@@ -152,7 +154,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
return nibblearray;
|
|
|
|
return dataLayer;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
long j = SectionPos.offset(sectionPos, Direction.UP);
|
|
|
|
long l = SectionPos.offset(sectionPos, Direction.UP);
|
|
|
|
- int k = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.get(SectionPos.getZeroNode(sectionPos));
|
|
|
|
- int i = (this.updatingSectionData).topSections.get(SectionPos.getZeroNode(sectionPos));
|
|
|
|
+ int k = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.getUpdating(SectionPos.getZeroNode(sectionPos)); // Paper - avoid copying light data
|
|
|
|
+ int i = (this.updatingSectionData).otherData.getUpdating(SectionPos.getZeroNode(sectionPos)); // Paper - avoid copying light data
|
|
|
|
|
|
|
|
if (i != (this.updatingSectionData).currentLowestY && SectionPos.y(l) < i) {
|
|
|
|
if (k != ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY && SectionPos.y(j) < k) {
|
|
|
|
DataLayer dataLayer2;
|
|
|
|
DataLayer nibblearray1;
|
|
|
|
while((dataLayer2 = this.getDataLayer(l, true)) == null) {
|
|
|
|
@@ -304,7 +306,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
@@ -260,7 +262,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
if (!this.columnsWithSkySources.contains(l)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
- int i1 = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.get(l);
|
|
|
|
|
|
|
|
+ int i1 = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.getUpdating(l); // Paper - avoid copying light data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SectionPos.sectionToBlockCoord(i1) == j + 16;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -313,7 +315,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected boolean isAboveData(long sectionPos) {
|
|
|
|
protected boolean isAboveData(long sectionPos) {
|
|
|
|
long j = SectionPos.getZeroNode(sectionPos);
|
|
|
|
long l = SectionPos.getZeroNode(sectionPos);
|
|
|
|
- int k = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.get(j);
|
|
|
|
- int i = (this.updatingSectionData).topSections.get(l);
|
|
|
|
+ int k = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.getUpdating(j); // Paper - avoid copying light data
|
|
|
|
+ int i = (this.updatingSectionData).otherData.getUpdating(l); // Paper - avoid copying light data
|
|
|
|
|
|
|
|
return i == (this.updatingSectionData).currentLowestY || SectionPos.y(sectionPos) >= i;
|
|
|
|
return k == ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY || SectionPos.y(sectionPos) >= k;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -327,18 +329,21 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
|
|
|
|
public static final class SkyDataLayerStorageMap extends DataLayerStorageMap<SkyLightSectionStorage.SkyDataLayerStorageMap> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int currentLowestY;
|
|
|
|
@@ -271,18 +273,21 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
|
|
|
|
- private final Long2IntOpenHashMap topSections;
|
|
|
|
|
|
|
|
|
|
|
|
protected static final class SkyDataLayerStorageMap extends DataLayerStorageMap<SkyLightSectionStorage.SkyDataLayerStorageMap> {
|
|
|
|
|
|
|
|
int currentLowestY;
|
|
|
|
|
|
|
|
- final Long2IntOpenHashMap topSections;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- public SkyDataLayerStorageMap(Long2ObjectOpenHashMap<DataLayer> arrays, Long2IntOpenHashMap columnToTopSection, int minSectionY) {
|
|
|
|
- public SkyDataLayerStorageMap(Long2ObjectOpenHashMap<DataLayer> arrays, Long2IntOpenHashMap columnToTopSection, int minSectionY) {
|
|
|
|
- super(arrays);
|
|
|
|
- super(arrays);
|
|
|
|
- this.topSections = columnToTopSection;
|
|
|
|
- this.topSections = columnToTopSection;
|
|
|
|
- columnToTopSection.defaultReturnValue(minSectionY);
|
|
|
|
- columnToTopSection.defaultReturnValue(minSectionY);
|
|
|
|
- this.currentLowestY = minSectionY;
|
|
|
|
|
|
|
|
+ private final com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int otherData; // Paper - avoid copying light data
|
|
|
|
+ private final com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int otherData; // Paper - avoid copying light data
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // Paper start - avoid copying light data
|
|
|
|
+ // Paper start - avoid copying light data
|
|
|
|
+ public SkyDataLayerStorageMap(com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<DataLayer> data, com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int otherData, int i, boolean isVisible) {
|
|
|
|
+ public SkyDataLayerStorageMap(com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<DataLayer> arrays, com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int columnToTopSection, int minSectionY, boolean isVisible) {
|
|
|
|
+ super(data, isVisible);
|
|
|
|
+ super(arrays, isVisible);
|
|
|
|
+ this.otherData = otherData;
|
|
|
|
+ this.otherData = columnToTopSection;
|
|
|
|
+ otherData.queueDefaultReturnValue(i);
|
|
|
|
+ otherData.queueDefaultReturnValue(minSectionY);
|
|
|
|
+ // Paper end - avoid copying light data
|
|
|
|
+ // Paper end
|
|
|
|
+ this.currentLowestY = i;
|
|
|
|
this.currentLowestY = minSectionY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|