- 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
}
@Override
@@ -23,13 +23,13 @@ public class BlockLightSectionStorage extends LayerLightSectionStorage<BlockLigh
public static final class BlockDataLayerStorageMap extends DataLayerStorageMap<BlockLightSectionStorage.BlockDataLayerStorageMap> {
- public BlockDataLayerStorageMap(Long2ObjectOpenHashMap<DataLayer> arrays) {
- super(arrays);
+ public BlockDataLayerStorageMap(com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object<DataLayer> long2objectopenhashmap, boolean isVisible) { // Paper - avoid copying light data
+ super(long2objectopenhashmap, isVisible); // Paper - avoid copying light data
}
@Override
public BlockLightSectionStorage.BlockDataLayerStorageMap copy() {
- return new BlockLightSectionStorage.BlockDataLayerStorageMap(this.map.clone());
+ return new BlockDataLayerStorageMap(this.data, true); // Paper - avoid copying light data
@@ -26,8 +26,8 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
protected final LongSet dataSectionSet = new LongOpenHashSet();
protected final LongSet toMarkNoData = new LongOpenHashSet();
protected final LongSet toMarkData = new LongOpenHashSet();
- 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 final M updatingSectionData; // Paper - diff on change, should be "updating"
protected final LongSet changedSections = new LongOpenHashSet();
protected final LongSet sectionsAffectedByLightUpdates = new LongOpenHashSet();
protected final Long2ObjectMap<DataLayer> queuedSections = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap());
@@ -41,8 +41,8 @@ public abstract class LayerLightSectionStorage<M extends DataLayerStorageMap<M>>
this.layer = lightType;
this.chunkSource = chunkProvider;
this.updatingSectionData = lightData;
- this.visibleSectionData = lightData.copy();
- this.visibleSectionData.disableCache();
+ this.e_visible = lightData.copy(); // Paper - avoid copying light data
+ this.e_visible.disableCache(); // Paper - avoid copying light data
- 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
- int l = lightenginestoragesky_a.topSections.get(SectionPos.getZeroNode(j));
+ 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
+ int l = lightenginestoragesky_a.otherData.getVisibleAsync(SectionPos.getZeroNode(j)); // Paper - avoid copying light data
if (l != lightenginestoragesky_a.currentLowestY && k < l) {
DataLayer nibblearray = this.getDataLayer(lightenginestoragesky_a, j); // Paper - decompile fix
@@ -52,6 +53,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
} else {
return 15;
}
+ } // Paper - avoid copying light data
}
@Override
@@ -60,14 +62,14 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
if (((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY > j) {
+ ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.queueUpdate(k, j + 1); // Paper - avoid copying light data
if (this.columnsWithSkySources.contains(k)) {
this.queueAddSource(sectionPos);
if (l > ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY) {
@@ -107,7 +109,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
int k = SectionPos.y(sectionPos);
- if (((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.get(j) == k + 1) {
+ if (((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.getUpdating(j) == k + 1) { // Paper - avoid copying light data
long l;
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)) {
- ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.put(j, k + 1);
+ ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.queueUpdate(j, k + 1); // Paper - avoid copying light data
if (enabled && this.columnsWithSkySources.add(columnPos)) {
- int j = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.get(columnPos);
+ int j = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.getUpdating(columnPos); // Paper - avoid copying light data
if (j != ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY) {
long k = SectionPos.asLong(SectionPos.x(columnPos), j - 1, SectionPos.z(columnPos));
@@ -161,7 +163,7 @@ public class SkyLightSectionStorage extends LayerLightSectionStorage<SkyLightSec
return nibblearray;
} else {
long j = SectionPos.offset(sectionPos, Direction.UP);
- int k = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).topSections.get(SectionPos.getZeroNode(sectionPos));
+ int k = ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).otherData.getUpdating(SectionPos.getZeroNode(sectionPos)); // Paper - avoid copying light data
if (k != ((SkyLightSectionStorage.SkyDataLayerStorageMap) this.updatingSectionData).currentLowestY && SectionPos.y(j) < k) {
DataLayer nibblearray1;
@@ -304,7 +306,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
+ private final com.destroystokyo.paper.util.map.QueuedChangesMapLong2Int otherData; // Paper - 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) {
+ super(data, isVisible);
+ this.otherData = otherData;
+ otherData.queueDefaultReturnValue(i);
+ // Paper end - avoid copying light data
+ this.currentLowestY = i;
}
@Override
public SkyLightSectionStorage.SkyDataLayerStorageMap copy() {
- return new SkyLightSectionStorage.SkyDataLayerStorageMap(this.map.clone(), this.topSections.clone(), this.currentLowestY);
+ this.otherData.performUpdatesLockMap(); // Paper - avoid copying light data
+ return new SkyLightSectionStorage.SkyDataLayerStorageMap(this.data, this.otherData, this.currentLowestY, true); // Paper - avoid copying light data