-
-
Save Spottedleaf/b6c366a3314e89f7c36375e554b736b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/java/com/tuinity/tuinity/chunk/light/StarLightEngine.java b/src/main/java/com/tuinity/tuinity/chunk/light/StarLightEngine.java | |
index e40cf190c..73e22a6da 100644 | |
--- a/src/main/java/com/tuinity/tuinity/chunk/light/StarLightEngine.java | |
+++ b/src/main/java/com/tuinity/tuinity/chunk/light/StarLightEngine.java | |
@@ -134,6 +134,10 @@ public abstract class StarLightEngine { | |
protected final int minSection; | |
protected final int maxSection; | |
+ public int blockGets; | |
+ public int lightGets; | |
+ public int lightSets; | |
+ | |
protected StarLightEngine(final boolean skylightPropagator, final World world) { | |
this.skylightPropagator = skylightPropagator; | |
this.emittedLightMask = skylightPropagator ? 0 : 0xF; | |
@@ -282,6 +286,7 @@ public abstract class StarLightEngine { | |
} | |
protected final IBlockData getBlockState(final int worldX, final int worldY, final int worldZ) { | |
+ ++blockGets; | |
final ChunkSection section = this.sectionCache[(worldX >> 4) + 5 * (worldZ >> 4) + (5 * 5) * (worldY >> 4) + this.chunkSectionIndexOffset]; | |
if (section != null) { | |
@@ -292,6 +297,7 @@ public abstract class StarLightEngine { | |
} | |
protected final IBlockData getBlockState(final int sectionIndex, final int localIndex) { | |
+ ++blockGets; | |
final ChunkSection section = this.sectionCache[sectionIndex]; | |
if (section != null) { | |
@@ -302,18 +308,21 @@ public abstract class StarLightEngine { | |
} | |
protected final int getLightLevel(final int worldX, final int worldY, final int worldZ) { | |
+ ++lightGets; | |
final SWMRNibbleArray nibble = this.nibbleCache[(worldX >> 4) + 5 * (worldZ >> 4) + (5 * 5) * (worldY >> 4) + this.chunkSectionIndexOffset]; | |
return nibble == null ? 0 : nibble.getUpdating((worldX & 15) | ((worldZ & 15) << 4) | ((worldY & 15) << 8)); | |
} | |
protected final int getLightLevel(final int sectionIndex, final int localIndex) { | |
+ ++lightGets; | |
final SWMRNibbleArray nibble = this.nibbleCache[sectionIndex]; | |
return nibble == null ? 0 : nibble.getUpdating(localIndex); | |
} | |
protected final void setLightLevel(final int worldX, final int worldY, final int worldZ, final int level) { | |
+ ++lightSets; | |
final int sectionIndex = (worldX >> 4) + 5 * (worldZ >> 4) + (5 * 5) * (worldY >> 4) + this.chunkSectionIndexOffset; | |
final SWMRNibbleArray nibble = this.nibbleCache[sectionIndex]; | |
@@ -338,6 +347,7 @@ public abstract class StarLightEngine { | |
} | |
protected final void postLightUpdate(final int worldX, final int worldY, final int worldZ) { | |
+ ++lightSets; | |
if (this.isClientSide) { | |
int cx1 = (worldX - 1) >> 4; | |
int cx2 = (worldX + 1) >> 4; | |
@@ -356,6 +366,7 @@ public abstract class StarLightEngine { | |
} | |
protected final void setLightLevel(final int sectionIndex, final int localIndex, final int worldX, final int worldY, final int worldZ, final int level) { | |
+ ++lightSets; | |
final SWMRNibbleArray nibble = this.nibbleCache[sectionIndex]; | |
if (nibble != null) { | |
@@ -1185,6 +1196,7 @@ public abstract class StarLightEngine { | |
final SWMRNibbleArray currentNibble = this.nibbleCache[sectionIndex]; | |
final int currentLevel; | |
+ ++lightGets; | |
if (currentNibble == null || (currentLevel = currentNibble.getUpdating(localIndex)) >= (propagatedLightLevel - 1)) { | |
continue; // already at the level we want or unloaded | |
} | |
@@ -1267,7 +1279,7 @@ public abstract class StarLightEngine { | |
final SWMRNibbleArray currentNibble = this.nibbleCache[sectionIndex]; | |
final int currentLevel; | |
- | |
+ ++lightGets; | |
if (currentNibble == null || (currentLevel = currentNibble.getUpdating(localIndex)) >= (propagatedLightLevel - 1)) { | |
continue; // already at the level we want | |
} | |
@@ -1371,7 +1383,7 @@ public abstract class StarLightEngine { | |
final SWMRNibbleArray currentNibble = this.nibbleCache[sectionIndex]; | |
final int lightLevel; | |
- | |
+ ++lightGets; | |
if (currentNibble == null || (lightLevel = currentNibble.getUpdating(localIndex)) == 0) { | |
// already at lowest (or unloaded), nothing we can do | |
continue; | |
@@ -1498,7 +1510,7 @@ public abstract class StarLightEngine { | |
final SWMRNibbleArray currentNibble = this.nibbleCache[sectionIndex]; | |
final int lightLevel; | |
- | |
+ ++lightGets; | |
if (currentNibble == null || (lightLevel = currentNibble.getUpdating(localIndex)) == 0) { | |
// already at lowest (or unloaded), nothing we can do | |
continue; | |
diff --git a/src/main/java/com/tuinity/tuinity/chunk/light/StarLightInterface.java b/src/main/java/com/tuinity/tuinity/chunk/light/StarLightInterface.java | |
index df686b974..e996f754b 100644 | |
--- a/src/main/java/com/tuinity/tuinity/chunk/light/StarLightInterface.java | |
+++ b/src/main/java/com/tuinity/tuinity/chunk/light/StarLightInterface.java | |
@@ -31,7 +31,7 @@ public final class StarLightInterface { | |
protected final ILightAccess lightAccess; | |
protected final ArrayDeque<SkyStarLightEngine> cachedSkyPropagators; | |
- protected final ArrayDeque<BlockStarLightEngine> cachedBlockPropagators; | |
+ public final ArrayDeque<BlockStarLightEngine> cachedBlockPropagators; | |
protected final Long2ObjectOpenHashMap<ChunkChanges> changedBlocks = new Long2ObjectOpenHashMap<>(); | |
diff --git a/src/main/java/net/minecraft/server/level/LightEngineThreaded.java b/src/main/java/net/minecraft/server/level/LightEngineThreaded.java | |
index 4d651cc21..ff4e62318 100644 | |
--- a/src/main/java/net/minecraft/server/level/LightEngineThreaded.java | |
+++ b/src/main/java/net/minecraft/server/level/LightEngineThreaded.java | |
@@ -1,6 +1,7 @@ | |
package net.minecraft.server.level; | |
import com.mojang.datafixers.util.Pair; | |
+import com.tuinity.tuinity.chunk.light.BlockStarLightEngine; | |
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap; // Paper | |
// Tuinity start | |
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; | |
@@ -27,6 +28,7 @@ import net.minecraft.world.level.chunk.IChunkAccess; | |
import net.minecraft.world.level.chunk.ILightAccess; | |
import net.minecraft.world.level.chunk.NibbleArray; | |
import net.minecraft.world.level.lighting.LightEngine; | |
+import net.minecraft.world.level.lighting.LightEngineBlock; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
@@ -583,6 +585,29 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable { | |
private final java.util.List<Runnable> post = new java.util.ArrayList<>(); | |
private void b() { | |
//final long start = System.nanoTime(); // TODO remove debug | |
+ int lightGetsBefore; | |
+ int lightSetsBefore; | |
+ int blockGetsBefore; | |
+ if (this.theLightEngine != null) { | |
+ BlockStarLightEngine blockEngine = this.theLightEngine.cachedBlockPropagators.peek(); | |
+ if (this.theLightEngine.cachedBlockPropagators.size() > 1) { | |
+ throw new IllegalStateException(); | |
+ } | |
+ if (blockEngine == null) { | |
+ lightGetsBefore = 0; | |
+ lightSetsBefore = 0; | |
+ blockGetsBefore = 0; | |
+ } else { | |
+ lightGetsBefore = blockEngine.lightGets; | |
+ lightSetsBefore = blockEngine.lightSets; | |
+ blockGetsBefore = blockEngine.blockGets; | |
+ } | |
+ } else { | |
+ LightEngineBlock lightEngine = (LightEngineBlock)this.a(EnumSkyBlock.BLOCK); | |
+ lightGetsBefore = lightEngine.lightGets; | |
+ lightSetsBefore = lightEngine.lightSets; | |
+ blockGetsBefore = lightEngine.blockGets; | |
+ } | |
if (queue.poll(pre, post)) { | |
pre.forEach(Runnable::run); | |
pre.clear(); | |
@@ -612,6 +637,36 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable { | |
// Paper end | |
//final long end = System.nanoTime(); // TODO remove debug | |
//System.out.println("Block updates took " + (end - start) * 1.0e-6 + "ms"); // TODO remove debug | |
+ int lightGetsAfter; | |
+ int lightSetsAfter; | |
+ int blockGetsAfter; | |
+ if (this.theLightEngine != null) { | |
+ BlockStarLightEngine blockEngine = this.theLightEngine.cachedBlockPropagators.peek(); | |
+ if (this.theLightEngine.cachedBlockPropagators.size() > 1) { | |
+ throw new IllegalStateException(); | |
+ } | |
+ if (blockEngine == null) { | |
+ lightGetsAfter = 0; | |
+ lightSetsAfter = 0; | |
+ blockGetsAfter = 0; | |
+ } else { | |
+ lightGetsAfter = blockEngine.lightGets; | |
+ lightSetsAfter = blockEngine.lightSets; | |
+ blockGetsAfter = blockEngine.blockGets; | |
+ } | |
+ } else { | |
+ LightEngineBlock lightEngine = (LightEngineBlock)this.a(EnumSkyBlock.BLOCK); | |
+ lightGetsAfter = lightEngine.lightGets; | |
+ lightSetsAfter = lightEngine.lightSets; | |
+ blockGetsAfter = lightEngine.blockGets; | |
+ } | |
+ | |
+ int lightGets = lightGetsAfter - lightGetsBefore; | |
+ int lightSets = lightSetsAfter - lightSetsBefore; | |
+ int blockGets = blockGetsAfter - blockGetsBefore; | |
+ System.out.println("Light gets: " + lightGets); | |
+ System.out.println("Light sets: " + lightSets); | |
+ System.out.println("Block gets: " + blockGets); | |
} | |
public void a(int i) { | |
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.java | |
index ec2b23848..a0a73dad2 100644 | |
--- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.java | |
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.java | |
@@ -145,6 +145,8 @@ public class ChunkRegionLoader { | |
return fluidtype == null || fluidtype == FluidTypes.EMPTY; | |
}, chunkcoordintpair, nbttagcompound1.getList("LiquidsToBeTicked", 9)); | |
boolean flag = (com.tuinity.tuinity.config.TuinityConfig.useNewLightEngine ? nbttagcompound1.getInt(STARLIGHT_VERSION_TAG) == STARLIGHT_LIGHT_VERSION : nbttagcompound1.getBoolean("isLightOn")); boolean canUseSkyLight = flag && getStatus(nbttagcompound).isAtLeastStatus(ChunkStatus.LIGHT); boolean canUseBlockLight = canUseSkyLight; // Tuinity | |
+ flag = false; | |
+ canUseBlockLight = canUseSkyLight = false; | |
NBTTagList nbttaglist = nbttagcompound1.getList("Sections", 10); | |
boolean flag1 = true; | |
ChunkSection[] achunksection = new ChunkSection[16]; | |
diff --git a/src/main/java/net/minecraft/world/level/lighting/LightEngineBlock.java b/src/main/java/net/minecraft/world/level/lighting/LightEngineBlock.java | |
index e8d241503..2b3a37972 100644 | |
--- a/src/main/java/net/minecraft/world/level/lighting/LightEngineBlock.java | |
+++ b/src/main/java/net/minecraft/world/level/lighting/LightEngineBlock.java | |
@@ -23,6 +23,7 @@ public final class LightEngineBlock extends LightEngineLayer<LightEngineStorageB | |
} | |
private int d(long i) { | |
+ ++blockGets; | |
// Paper start - inline math | |
int j = (int) (i >> 38); | |
int k = (int) ((i << 52) >> 52); | |
@@ -88,7 +89,7 @@ public final class LightEngineBlock extends LightEngineLayer<LightEngineStorageB | |
for (int i1 = 0; i1 < l; ++i1) { | |
EnumDirection enumdirection = aenumdirection[i1]; | |
long j1 = BlockPosition.getAdjacent(x, y, z, enumdirection); // Paper | |
- long k1 = SectionPosition.getAdjacentFromBlockPos(x, y, z, enumdirection); // Paper | |
+ long k1 = SectionPosition.blockToSection(j1); // fix paper's lighting... see https://github.com/PaperMC/Paper/commit/0a9b89c7a84ed7affccad806277bcca0a7d44eaa. Yes I fixed it by running into this issue during the test. | |
if (k == k1 || ((LightEngineStorageBlock) this.c).g(k1)) { | |
this.b(i, j1, j, flag); | |
diff --git a/src/main/java/net/minecraft/world/level/lighting/LightEngineLayer.java b/src/main/java/net/minecraft/world/level/lighting/LightEngineLayer.java | |
index 64dad8ed7..d4e28d057 100644 | |
--- a/src/main/java/net/minecraft/world/level/lighting/LightEngineLayer.java | |
+++ b/src/main/java/net/minecraft/world/level/lighting/LightEngineLayer.java | |
@@ -28,10 +28,15 @@ public abstract class LightEngineLayer<M extends LightEngineStorageArray<M>, S e | |
private final long[] g = new long[2]; | |
private final IChunkAccess[] h = new IChunkAccess[2]; // Paper | |
+ public int blockGets; | |
+ public int lightGets; | |
+ public int lightSets; | |
+ | |
// Paper start - see fully commented out method below (look for Bedrock) | |
// optimized method with less branching for when scenarios arent needed. | |
// avoid using mutable version if can | |
protected final IBlockData getBlockOptimized(int x, int y, int z, MutableInt mutableint) { | |
+ ++blockGets; | |
IChunkAccess iblockaccess = this.a(x >> 4, z >> 4); | |
if (iblockaccess == null) { | |
@@ -45,6 +50,7 @@ public abstract class LightEngineLayer<M extends LightEngineStorageArray<M>, S e | |
} | |
} | |
protected final IBlockData getBlockOptimized(int x, int y, int z) { | |
+ ++blockGets; | |
IChunkAccess iblockaccess = this.a(x >> 4, z >> 4); | |
if (iblockaccess == null) { | |
@@ -168,11 +174,13 @@ public abstract class LightEngineLayer<M extends LightEngineStorageArray<M>, S e | |
protected int getNibbleLightInverse(NibbleArray nibblearray, int x, int y, int z) { return 15 - nibblearray.a(x & 15, y & 15, z & 15); } // Paper - x/y/z version of below | |
protected int a(NibbleArray nibblearray, long i) { | |
+ ++lightGets; | |
return 15 - nibblearray.a((int) (i >> 38) & 15, (int) ((i << 52) >> 52) & 15, (int) ((i << 26) >> 38) & 15); // Paper | |
} | |
@Override | |
protected void a(long i, int j) { | |
+ ++lightSets; | |
this.c.b(i, Math.min(15, 15 - j)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment