2019-04-22 23:36:14 +02:00
|
|
|
From c630ddd10b4711ffcd5318829821fb44f48294df Mon Sep 17 00:00:00 2001
|
2018-08-30 04:12:17 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Wed, 29 Aug 2018 21:59:22 -0400
|
|
|
|
Subject: [PATCH] Optimize getChunkIfLoaded type calls
|
|
|
|
|
|
|
|
Uses optimized check to avoid major locks and large method.
|
|
|
|
|
|
|
|
Will improve inlining across many hot methods.
|
|
|
|
|
|
|
|
Improve getBrightness to not do double chunk map lookups.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2019-04-06 05:08:45 +02:00
|
|
|
index 41926a361b..186cfda7e4 100644
|
2018-08-30 04:12:17 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2019-01-04 20:19:36 +01:00
|
|
|
@@ -379,7 +379,7 @@ public class ChunkProviderServer implements IChunkProvider {
|
2018-08-30 04:12:17 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
- Chunk neighbor = this.getChunkAt(chunk.locX + x, chunk.locZ + z, false, false);
|
|
|
|
+ Chunk neighbor = this.chunks.get(chunk.chunkKey); // Paper
|
|
|
|
if (neighbor != null) {
|
|
|
|
neighbor.setNeighborUnloaded(-x, -z);
|
|
|
|
chunk.setNeighborUnloaded(x, z);
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2019-04-06 05:08:45 +02:00
|
|
|
index 14f419deb8..630ebfb37c 100644
|
2018-08-30 04:12:17 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2019-02-03 16:34:04 +01:00
|
|
|
@@ -162,7 +162,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2018-08-30 04:12:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Chunk getChunkIfLoaded(int x, int z) {
|
|
|
|
- return ((ChunkProviderServer) this.chunkProvider).getChunkAt(x, z, false, false);
|
|
|
|
+ return ((ChunkProviderServer) this.chunkProvider).chunks.get(ChunkCoordIntPair.a(x, z)); // Paper - optimize getChunkIfLoaded
|
|
|
|
}
|
|
|
|
|
|
|
|
protected World(IDataManager idatamanager, @Nullable PersistentCollection persistentcollection, WorldData worlddata, WorldProvider worldprovider, MethodProfiler methodprofiler, boolean flag, ChunkGenerator gen, org.bukkit.World.Environment env) {
|
2019-02-03 16:34:04 +01:00
|
|
|
@@ -724,7 +724,8 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2018-08-30 04:12:17 +02:00
|
|
|
blockposition = new BlockPosition(blockposition.getX(), 0, blockposition.getZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
- return !blockposition.isValidLocation() ? enumskyblock.c : (!this.isLoaded(blockposition) ? enumskyblock.c : this.getChunkAtWorldCoords(blockposition).getBrightness(enumskyblock, blockposition)); // Paper
|
|
|
|
+ Chunk chunk; // Paper
|
|
|
|
+ return !blockposition.isValidLocation() ? enumskyblock.c : ((chunk = this.getChunkIfLoaded(blockposition)) == null ? enumskyblock.c : chunk.getBrightness(enumskyblock, blockposition)); // Paper - optimize ifChunkLoaded
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(EnumSkyBlock enumskyblock, BlockPosition blockposition, int i) {
|
2019-04-06 05:08:45 +02:00
|
|
|
@@ -1959,7 +1960,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2018-08-30 04:12:17 +02:00
|
|
|
if (blockposition.isInvalidYLocation()) { // Paper
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
- Chunk chunk = this.chunkProvider.getChunkAt(blockposition.getX() >> 4, blockposition.getZ() >> 4, false, false);
|
|
|
|
+ Chunk chunk = this.getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4); // Paper - optimize ifLoaded
|
|
|
|
|
|
|
|
return chunk != null && !chunk.isEmpty();
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2019-04-06 05:08:45 +02:00
|
|
|
index 72eb8ed4f4..7e52859c1d 100644
|
2018-08-30 04:12:17 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -218,7 +218,7 @@ public class CraftWorld implements World {
|
2018-08-30 04:12:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-17 06:18:06 +01:00
|
|
|
- net.minecraft.server.Chunk chunk = world.getChunkProvider().getChunkAt(x, z, false, false);
|
2018-08-30 04:12:17 +02:00
|
|
|
+ net.minecraft.server.Chunk chunk = world.getChunkIfLoaded(x, z); // Paper - optimize ifLaoded
|
|
|
|
if (chunk != null) {
|
2018-12-17 06:18:06 +01:00
|
|
|
world.getChunkProvider().unload(chunk);
|
2018-08-30 04:12:17 +02:00
|
|
|
}
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -237,7 +237,7 @@ public class CraftWorld implements World {
|
2018-08-30 04:12:17 +02:00
|
|
|
|
|
|
|
private boolean unloadChunk0(int x, int z, boolean save) {
|
|
|
|
Boolean result = MCUtil.ensureMain("Unload Chunk", () -> { // Paper - Ensure never async
|
2018-12-17 06:18:06 +01:00
|
|
|
- net.minecraft.server.Chunk chunk = world.getChunkProvider().getChunkAt(x, z, false, false);
|
2018-08-30 04:12:17 +02:00
|
|
|
+ net.minecraft.server.Chunk chunk = world.getChunkIfLoaded(x, z); // Paper - optimize ifLoaded
|
|
|
|
if (chunk == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
--
|
2019-03-20 02:46:00 +01:00
|
|
|
2.21.0
|
2018-08-30 04:12:17 +02:00
|
|
|
|