testserver/Spigot-Server-Patches/0065-ChunkMap-caching.patch

141 lines
5.6 KiB
Diff
Raw Normal View History

From f3941c39661065a2384905328005c8699efbb9f9 Mon Sep 17 00:00:00 2001
2015-07-15 09:42:49 +00:00
From: Iceee <andrew@opticgaming.tv>
Date: Wed, 15 Jul 2015 02:41:12 -0700
Subject: [PATCH] ChunkMap caching
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index ab4de94..d5f13c0 100644
2015-07-15 09:42:49 +00:00
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -50,6 +50,49 @@ public class Chunk {
2015-07-15 09:42:49 +00:00
public long lightUpdateTime;
// PaperSpigot end
+ // PaperSpigot start - ChunkMap caching
+ private PacketPlayOutMapChunk.ChunkMap chunkMap;
2015-07-15 20:31:34 +00:00
+ private int emptySectionBits;
2015-07-15 09:42:49 +00:00
+
+ public PacketPlayOutMapChunk.ChunkMap getChunkMap(boolean groundUpContinuous, int primaryBitMask) {
+ if (!world.paperSpigotConfig.cacheChunkMaps || !groundUpContinuous || (primaryBitMask != 0 && primaryBitMask != '\uffff')) {
+ return PacketPlayOutMapChunk.a(this, groundUpContinuous, !world.worldProvider.o(), primaryBitMask);
+ }
+
+ if (primaryBitMask == 0) {
+ PacketPlayOutMapChunk.ChunkMap chunkMap = new PacketPlayOutMapChunk.ChunkMap();
+ chunkMap.a = new byte[0];
+ return chunkMap;
2015-07-15 23:16:27 +00:00
+ }
+
2015-07-15 20:31:34 +00:00
+ boolean isDirty = false;
+ for (int i = 0; i < sections.length; ++i) {
+ ChunkSection section = sections[i];
+ if (section == null) {
+ if ((emptySectionBits & (1 << i)) == 0) {
+ isDirty = true;
+ emptySectionBits |= (1 << i);
+ }
+ } else {
+ if ((emptySectionBits & (1 << i)) == 1) {
+ isDirty = true;
+ emptySectionBits &= ~(1 << i);
+ section.isDirty = false;
+ } else if (section.isDirty) {
+ isDirty = true;
+ section.isDirty = false;
+ }
2015-07-15 09:42:49 +00:00
+ }
2015-07-15 20:31:34 +00:00
+ }
2015-07-15 09:42:49 +00:00
+
2015-07-15 20:31:34 +00:00
+ if (isDirty || chunkMap == null) {
+ chunkMap = PacketPlayOutMapChunk.a(this, true, !world.worldProvider.o(), '\uffff');
2015-07-15 09:42:49 +00:00
+ }
2015-07-15 20:31:34 +00:00
+
+ return chunkMap;
2015-07-15 09:42:49 +00:00
+ }
+ // PaperSpigot end
+
// CraftBukkit start - Neighbor loaded cache for chunk lighting and entity ticking
private int neighbors = 0x1 << 12;
2015-07-15 20:31:34 +00:00
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java
index f734ab0..907c57b 100644
--- a/src/main/java/net/minecraft/server/ChunkSection.java
+++ b/src/main/java/net/minecraft/server/ChunkSection.java
@@ -8,6 +8,7 @@ public class ChunkSection {
private char[] blockIds;
private NibbleArray emittedLight;
private NibbleArray skyLight;
+ boolean isDirty; // PaperSpigot
public ChunkSection(int i, boolean flag) {
this.yPos = i;
@@ -57,6 +58,7 @@ public class ChunkSection {
}
this.blockIds[j << 8 | k << 4 | i] = (char) Block.d.b(iblockdata);
+ isDirty = true; // PaperSpigot
2015-07-15 09:42:49 +00:00
}
2015-07-15 20:31:34 +00:00
public Block b(int i, int j, int k) {
@@ -83,6 +85,7 @@ public class ChunkSection {
public void a(int i, int j, int k, int l) {
this.skyLight.a(i, j, k, l);
+ isDirty = true; // PaperSpigot
}
public int d(int i, int j, int k) {
@@ -91,6 +94,7 @@ public class ChunkSection {
public void b(int i, int j, int k, int l) {
this.emittedLight.a(i, j, k, l);
+ isDirty = true; // PaperSpigot
}
public int e(int i, int j, int k) {
2015-07-15 09:42:49 +00:00
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
index 58c0275..a0021fb 100644
2015-07-15 09:42:49 +00:00
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
@@ -18,7 +18,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
this.a = chunk.locX;
this.b = chunk.locZ;
this.d = flag;
- this.c = a(chunk, flag, !chunk.getWorld().worldProvider.o(), i);
+ this.c = chunk.getChunkMap(flag, i); // PaperSpigot
2015-07-15 09:42:49 +00:00
chunk.world.spigotConfig.antiXrayInstance.obfuscateSync(chunk.locX, chunk.locZ, c.b, c.a, chunk.world);
}
2015-07-15 20:31:34 +00:00
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java
index 10c0e34..00c0538 100644
2015-07-15 20:31:34 +00:00
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java
@@ -23,7 +23,7 @@ public class PacketPlayOutMapChunkBulk implements Packet<PacketListenerPlayOut>
for (int j = 0; j < i; ++j) {
Chunk chunk = (Chunk) list.get(j);
- PacketPlayOutMapChunk.ChunkMap packetplayoutmapchunk_chunkmap = PacketPlayOutMapChunk.a(chunk, true, this.d, '\uffff');
+ PacketPlayOutMapChunk.ChunkMap packetplayoutmapchunk_chunkmap = chunk.getChunkMap(true, '\uffff'); // PaperSpigot
2015-07-15 09:42:49 +00:00
2015-07-15 20:31:34 +00:00
this.a[j] = chunk.locX;
this.b[j] = chunk.locZ;
2015-07-15 23:16:27 +00:00
diff --git a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
index 9c8a01b..cde11b2 100644
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
@@ -390,4 +390,10 @@ public class PaperSpigotWorldConfig
{
mobSpawnerTickRate = getInt( "mob-spawner-tick-rate", 1 );
}
+
+ public boolean cacheChunkMaps;
+ private void cacheChunkMaps()
+ {
+ cacheChunkMaps = getBoolean( "cache-chunk-maps", false );
+ }
}
2015-07-15 09:42:49 +00:00
--
1.9.5.msysgit.1