2018-08-11 04:13:00 +02:00
|
|
|
From decdf8c2fb732471cb74652271e9ad351d74a207 Mon Sep 17 00:00:00 2001
|
2016-06-19 05:33:57 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 18 Jun 2016 23:22:12 -0400
|
|
|
|
Subject: [PATCH] Delay Chunk Unloads based on Player Movement
|
|
|
|
|
|
|
|
When players are moving in the world, doing things such as building or exploring,
|
|
|
|
they will commonly go back and forth in a small area. This causes a ton of chunk load
|
|
|
|
and unload activity on the edge chunks of their view distance.
|
|
|
|
|
|
|
|
A simple back and forth movement in 6 blocks could spam a chunk to thrash a
|
|
|
|
loading and unload cycle over and over again.
|
|
|
|
|
|
|
|
This is very wasteful. This system introduces a delay of inactivity on a chunk
|
|
|
|
before it actually unloads, which is maintained separately from ChunkGC.
|
|
|
|
|
|
|
|
This allows servers with smaller worlds who do less long distance exploring to stop
|
|
|
|
wasting cpu cycles on saving/unloading/reloading chunks repeatedly.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2018-08-06 01:46:43 +02:00
|
|
|
index 41e73b3409..ec6b550ff6 100644
|
2016-06-19 05:33:57 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2018-07-24 02:24:44 +02:00
|
|
|
@@ -285,4 +285,18 @@ public class PaperWorldConfig {
|
2018-07-16 22:08:09 +02:00
|
|
|
preventTntFromMovingInWater = getBoolean("prevent-tnt-from-moving-in-water", false);
|
|
|
|
log("Prevent TNT from moving in water: " + preventTntFromMovingInWater);
|
2016-06-19 05:33:57 +02:00
|
|
|
}
|
2016-07-29 03:54:48 +02:00
|
|
|
+
|
2016-06-19 05:33:57 +02:00
|
|
|
+ public long delayChunkUnloadsBy;
|
|
|
|
+ private void delayChunkUnloadsBy() {
|
2016-07-29 03:57:36 +02:00
|
|
|
+ delayChunkUnloadsBy = PaperConfig.getSeconds(getString("delay-chunk-unloads-by", "10s"));
|
2016-06-19 05:33:57 +02:00
|
|
|
+ if (delayChunkUnloadsBy > 0) {
|
|
|
|
+ log("Delaying chunk unloads by " + delayChunkUnloadsBy + " seconds");
|
|
|
|
+ delayChunkUnloadsBy *= 1000;
|
|
|
|
+ }
|
2018-05-30 22:31:55 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean skipEntityTickingInChunksScheduledForUnload = true;
|
|
|
|
+ private void skipEntityTickingInChunksScheduledForUnload() {
|
2018-05-30 22:38:27 +02:00
|
|
|
+ skipEntityTickingInChunksScheduledForUnload = getBoolean("skip-entity-ticking-in-chunks-scheduled-for-unload", skipEntityTickingInChunksScheduledForUnload);
|
2016-06-19 05:33:57 +02:00
|
|
|
+ }
|
2016-07-29 03:54:48 +02:00
|
|
|
}
|
2016-06-19 05:33:57 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2018-08-06 01:46:43 +02:00
|
|
|
index 63ca61c1d6..ace64c0345 100644
|
2016-06-19 05:33:57 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2018-07-16 22:08:09 +02:00
|
|
|
@@ -39,6 +39,7 @@ public class Chunk implements IChunkAccess {
|
2018-07-06 00:39:43 +02:00
|
|
|
private boolean j; public boolean isLoaded() { return j; } // Paper - OBFHELPER
|
2016-06-19 05:33:57 +02:00
|
|
|
public final World world;
|
2018-07-16 22:08:09 +02:00
|
|
|
public final Map<HeightMap.Type, HeightMap> heightMap;
|
2016-06-19 05:33:57 +02:00
|
|
|
+ public Long scheduledForUnload; // Paper - delay chunk unloads
|
|
|
|
public final int locX;
|
|
|
|
public final int locZ;
|
|
|
|
private boolean m;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2018-08-06 01:46:43 +02:00
|
|
|
index 2925c345a1..a5139b0b0d 100644
|
2016-06-19 05:33:57 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2018-07-26 01:05:07 +02:00
|
|
|
@@ -328,6 +328,19 @@ public class ChunkProviderServer implements IChunkProvider {
|
2017-01-31 05:33:54 +01:00
|
|
|
|
|
|
|
activityAccountant.endActivity(); // Spigot
|
2016-06-19 05:33:57 +02:00
|
|
|
}
|
|
|
|
+ // Paper start - delayed chunk unloads
|
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
|
+ long unloadAfter = world.paperConfig.delayChunkUnloadsBy;
|
|
|
|
+ if (unloadAfter > 0) {
|
|
|
|
+ //noinspection Convert2streamapi
|
|
|
|
+ for (Chunk chunk : chunks.values()) {
|
|
|
|
+ if (chunk.scheduledForUnload != null && now - chunk.scheduledForUnload > unloadAfter) {
|
|
|
|
+ chunk.scheduledForUnload = null;
|
|
|
|
+ unload(chunk);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
2018-07-16 22:08:09 +02:00
|
|
|
this.f.a();
|
2017-05-14 20:05:01 +02:00
|
|
|
this.chunkLoader.b();
|
2016-06-19 05:33:57 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
|
2018-08-06 01:46:43 +02:00
|
|
|
index ffff87dc03..344b95233f 100644
|
2016-06-19 05:33:57 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
|
2018-07-16 22:08:09 +02:00
|
|
|
@@ -33,14 +33,23 @@ public class PlayerChunk {
|
2016-06-19 05:33:57 +02:00
|
|
|
public void run() {
|
|
|
|
loadInProgress = false;
|
|
|
|
PlayerChunk.this.chunk = PlayerChunk.this.playerChunkMap.getWorld().getChunkProviderServer().getOrLoadChunkAt(location.x, location.z);
|
|
|
|
+ markChunkUsed(); // Paper - delay chunk unloads
|
|
|
|
}
|
|
|
|
};
|
|
|
|
+ // Paper start - delay chunk unloads
|
|
|
|
+ public final void markChunkUsed() {
|
|
|
|
+ if (chunk != null && chunk.scheduledForUnload != null) {
|
|
|
|
+ chunk.scheduledForUnload = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public PlayerChunk(PlayerChunkMap playerchunkmap, int i, int j) {
|
2018-07-16 22:08:09 +02:00
|
|
|
this.playerChunkMap = playerchunkmap;
|
|
|
|
this.location = new ChunkCoordIntPair(i, j);
|
|
|
|
this.chunk = playerchunkmap.getWorld().getChunkProviderServer().getOrLoadChunkAt(i, j);
|
2016-06-19 05:33:57 +02:00
|
|
|
+ markChunkUsed(); // Paper - delay chunk unloads
|
|
|
|
}
|
|
|
|
|
2018-07-16 22:08:09 +02:00
|
|
|
public ChunkCoordIntPair a() {
|
|
|
|
@@ -85,6 +94,7 @@ public class PlayerChunk {
|
|
|
|
this.chunk = this.playerChunkMap.getWorld().getChunkProviderServer().getChunkAt(this.location.x, this.location.z);
|
|
|
|
} else {
|
|
|
|
this.chunk = this.playerChunkMap.getWorld().getChunkProviderServer().getOrLoadChunkAt(this.location.x, this.location.z);
|
2016-06-19 05:33:57 +02:00
|
|
|
+ markChunkUsed(); // Paper - delay chunk unloads
|
|
|
|
}
|
|
|
|
|
2018-07-16 22:08:09 +02:00
|
|
|
return this.chunk != null;
|
2016-06-19 05:33:57 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2018-08-06 01:46:43 +02:00
|
|
|
index 4d888d6d4f..cf5c76a78e 100644
|
2016-06-19 05:33:57 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2018-07-16 22:08:09 +02:00
|
|
|
@@ -461,7 +461,13 @@ public class PlayerChunkMap {
|
2016-06-19 05:33:57 +02:00
|
|
|
Chunk chunk = playerchunk.f();
|
|
|
|
|
|
|
|
if (chunk != null) {
|
|
|
|
- this.getWorld().getChunkProviderServer().unload(chunk);
|
|
|
|
+ // Paper start - delay chunk unloads
|
|
|
|
+ if (world.paperConfig.delayChunkUnloadsBy <= 0) {
|
|
|
|
+ this.getWorld().getChunkProviderServer().unload(chunk);
|
|
|
|
+ } else {
|
|
|
|
+ chunk.scheduledForUnload = System.currentTimeMillis();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-05-30 22:31:55 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2018-08-06 01:46:43 +02:00
|
|
|
index 7dae87199e..b6efd8506b 100644
|
2018-05-30 22:31:55 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2018-07-29 18:42:07 +02:00
|
|
|
@@ -1305,7 +1305,13 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
2018-07-16 22:08:09 +02:00
|
|
|
if (!tileentity.x() && tileentity.u()) {
|
2018-05-30 22:31:55 +02:00
|
|
|
BlockPosition blockposition = tileentity.getPosition();
|
|
|
|
|
2018-07-16 22:08:09 +02:00
|
|
|
- if (this.isLoaded(blockposition) && this.K.a(blockposition)) {
|
2018-05-30 22:31:55 +02:00
|
|
|
+ // Paper start - Skip ticking in chunks scheduled for unload
|
|
|
|
+ net.minecraft.server.Chunk chunk = this.getChunkIfLoaded(blockposition);
|
|
|
|
+ boolean shouldTick = chunk != null;
|
|
|
|
+ if(this.paperConfig.skipEntityTickingInChunksScheduledForUnload)
|
|
|
|
+ shouldTick = shouldTick && !chunk.isUnloading() && chunk.scheduledForUnload == null;
|
2018-07-16 22:08:09 +02:00
|
|
|
+ if (shouldTick && this.K.a(blockposition)) {
|
2018-05-30 22:31:55 +02:00
|
|
|
+ // Paper end
|
|
|
|
try {
|
|
|
|
this.methodProfiler.a(() -> {
|
2018-07-16 22:08:09 +02:00
|
|
|
return String.valueOf(TileEntityTypes.a(tileentity.C()));
|
2016-06-19 05:33:57 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2018-08-11 04:13:00 +02:00
|
|
|
index 907791a5f1..579e783d11 100644
|
2016-06-19 05:33:57 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2018-08-11 04:13:00 +02:00
|
|
|
@@ -1616,7 +1616,7 @@ public class CraftWorld implements World {
|
2016-06-19 05:33:57 +02:00
|
|
|
ChunkProviderServer cps = world.getChunkProviderServer();
|
|
|
|
for (net.minecraft.server.Chunk chunk : cps.chunks.values()) {
|
|
|
|
// If in use, skip it
|
|
|
|
- if (isChunkInUse(chunk.locX, chunk.locZ)) {
|
|
|
|
+ if (isChunkInUse(chunk.locX, chunk.locZ) || chunk.scheduledForUnload != null) { // Paper - delayed chunk unloads
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-05-30 22:31:55 +02:00
|
|
|
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
|
2018-08-06 01:46:43 +02:00
|
|
|
index a9b84fdec4..e02647f806 100644
|
2018-05-30 22:31:55 +02:00
|
|
|
--- a/src/main/java/org/spigotmc/ActivationRange.java
|
|
|
|
+++ b/src/main/java/org/spigotmc/ActivationRange.java
|
2018-07-16 22:08:09 +02:00
|
|
|
@@ -284,6 +284,10 @@ public class ActivationRange
|
2018-05-30 22:31:55 +02:00
|
|
|
{
|
|
|
|
isActive = false;
|
|
|
|
}
|
|
|
|
+ // Paper start - Skip ticking in chunks scheduled for unload
|
|
|
|
+ if(entity.world.paperConfig.skipEntityTickingInChunksScheduledForUnload && (chunk == null || chunk.isUnloading() || chunk.scheduledForUnload != null))
|
|
|
|
+ isActive = false;
|
|
|
|
+ // Paper end
|
|
|
|
return isActive;
|
|
|
|
}
|
|
|
|
}
|
2016-06-19 05:33:57 +02:00
|
|
|
--
|
2018-07-04 09:55:24 +02:00
|
|
|
2.18.0
|
2016-06-19 05:33:57 +02:00
|
|
|
|