Fix lag caused by water lighting updates

Before: http://aikar.co/timings.php?url=7842564
After: http://aikar.co/timings.php?url=7842536
This commit is contained in:
Iceee 2014-07-23 10:53:28 -05:00 committed by Zach Brown
parent f07313c43f
commit c768de882c

View file

@ -0,0 +1,105 @@
From ff141325520b2a64ed66c1e224df6b5e07096025 Mon Sep 17 00:00:00 2001
From: Iceee <andrew@opticgaming.tv>
Date: Wed, 23 Jul 2014 09:42:45 -0500
Subject: [PATCH] Better water lighting updates
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 406aead..d284614 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -42,6 +42,12 @@ public class Chunk {
private int x;
protected net.minecraft.util.gnu.trove.map.hash.TObjectIntHashMap<Class> entityCount = new net.minecraft.util.gnu.trove.map.hash.TObjectIntHashMap<Class>(); // Spigot
+ // PaperSpigot start
+ private boolean waterLightingChanged;
+ private boolean[] waterChanges;
+ private int ticks;
+ // PaperSpigot end
+
// CraftBukkit start - Neighbor loaded cache for chunk lighting and entity ticking
private int neighbors = 0x1 << 12;
@@ -75,6 +81,9 @@ public class Chunk {
this.v = new byte[256];
this.b = new int[256];
this.c = new boolean[256];
+ // PaperSpigot start
+ this.waterChanges = new boolean[256];
+ // PaperSpigot end
this.tileEntities = new HashMap();
this.x = 4096;
this.entitySlices = new List[16];
@@ -231,6 +240,14 @@ public class Chunk {
this.n = true;
}
+ // PaperSpigot start
+ private void scheduleWaterLightingUpdate(int i, int j) {
+ this.waterChanges[i + j * 16] = true;
+ this.waterLightingChanged = true;
+ }
+
+ // PaperSpigot end
+
private void e(int i, int j) {
this.c[i + j * 16] = true;
this.w = true;
@@ -241,8 +258,11 @@ public class Chunk {
if (this.world.areChunksLoaded(this.locX * 16 + 8, 0, this.locZ * 16 + 8, 16)) {
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
- if (this.c[i + j * 16]) {
+ // PaperSpigot start
+ if (this.c[i + j * 16] || this.waterChanges[i + j * 16]) {
this.c[i + j * 16] = false;
+ this.waterChanges[i + j * 16] = false;
+ // PaperSpigot end
int k = this.b(i, j);
int l = this.locX * 16 + i;
int i1 = this.locZ * 16 + j;
@@ -277,6 +297,9 @@ public class Chunk {
}
this.w = false;
+ // PaperSpigot start
+ this.waterLightingChanged = false;
+ // PaperSpigot end
}
this.world.methodProfiler.b();
@@ -507,7 +530,13 @@ public class Chunk {
}
if (j2 != k2 && (j2 < k2 || this.getBrightness(EnumSkyBlock.SKY, i, j, k) > 0 || this.getBrightness(EnumSkyBlock.BLOCK, i, j, k) > 0)) {
- this.e(i, k);
+ // PaperSpigot start
+ if(block.material == Material.WATER) {
+ this.scheduleWaterLightingUpdate(i, k);
+ } else {
+ this.e(i, k);
+ }
+ // PaperSpigot end
}
}
@@ -961,9 +990,14 @@ public class Chunk {
}
public void b(boolean flag) {
- if (this.w && !this.world.worldProvider.g && !flag) {
+ // PaperSpigot start
+ ++ticks;
+ if(ticks % 20 == 0 && this.waterLightingChanged) {
+ this.c(this.world.isStatic);
+ } else if (this.w && !this.world.worldProvider.g && !flag) {
this.c(this.world.isStatic);
}
+ // PaperSpigot end
this.m = true;
if (!this.lit && this.done && this.world.spigotConfig.randomLightUpdates) { // Spigot - also use random light updates setting to determine if we should relight
--
1.9.4.msysgit.0