Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/CraftBukkit-Patches/0049-Entity-ticking-chunk-caching.patch

67 Zeilen
3.3 KiB
Diff

From e162863cd42ceef3bd6333aa4c7c05b632b7536e Mon Sep 17 00:00:00 2001
2013-07-16 13:21:55 +02:00
From: Ammar Askar <ammar@ammaraskar.com>
Date: Tue, 16 Jul 2013 03:32:32 +0500
Subject: [PATCH] Entity ticking chunk caching
Cache known loaded chunks so we avoid making a potentially expensive contains call for every single entity in exchange for some simple arithmetic. Best case scenario, this cuts down contains call to once per chunk, worst case it adds on some simple arithmetic operations
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2013-12-01 06:02:56 +01:00
index baa5d55..c4978f6 100644
2013-07-16 13:21:55 +02:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2013-12-01 06:02:56 +01:00
@@ -1192,6 +1192,7 @@ public abstract class World implements IBlockAccess {
2013-07-16 13:21:55 +02:00
CrashReport crashreport;
CrashReportSystemDetails crashreportsystemdetails;
+ long lastChunk = Long.MIN_VALUE; // Spigot - cache chunk x, z cords for unload queue
for (i = 0; i < this.i.size(); ++i) {
entity = (Entity) this.i.get(i);
// CraftBukkit start - Fixed an NPE, don't process entities in chunks queued for unload
2013-12-01 06:02:56 +01:00
@@ -1200,10 +1201,15 @@ public abstract class World implements IBlockAccess {
2013-07-16 13:21:55 +02:00
}
ChunkProviderServer chunkProviderServer = ((WorldServer) this).chunkProviderServer;
- if (chunkProviderServer.unloadQueue.contains(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4)) {
- continue;
+ // Spigot start - check last chunk to see if this loaded (fast cache)
+ long chunk = org.bukkit.craftbukkit.util.LongHash.toLong(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4);
+ if (lastChunk != chunk) {
+ if (chunkProviderServer.unloadQueue.contains(chunk)) { // Spigot end
+ continue;
+ }
}
// CraftBukkit end
+ lastChunk = chunk; // Spigot
try {
++entity.ticksLived;
2013-12-01 06:02:56 +01:00
@@ -1224,6 +1230,7 @@ public abstract class World implements IBlockAccess {
2013-07-16 13:21:55 +02:00
this.i.remove(i--);
}
}
+ lastChunk = Long.MIN_VALUE; // Spigot
this.methodProfiler.c("remove");
this.entityList.removeAll(this.f);
2013-12-01 06:02:56 +01:00
@@ -1254,10 +1261,15 @@ public abstract class World implements IBlockAccess {
2013-07-16 13:21:55 +02:00
// CraftBukkit start - Don't tick entities in chunks queued for unload
ChunkProviderServer chunkProviderServer = ((WorldServer) this).chunkProviderServer;
- if (chunkProviderServer.unloadQueue.contains(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4)) {
- continue;
+ // Spigot start - check last chunk to see if this loaded (fast cache)
+ long chunk = org.bukkit.craftbukkit.util.LongHash.toLong(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4);
+ if (lastChunk != chunk) {
+ if (chunkProviderServer.unloadQueue.contains(chunk)) { // Spigot end
+ continue;
+ }
}
// CraftBukkit end
+ lastChunk = Long.MIN_VALUE; // Spigot
2013-07-16 13:21:55 +02:00
if (entity.vehicle != null) {
if (!entity.vehicle.dead && entity.vehicle.passenger == entity) {
--
2013-11-27 12:01:50 +01:00
1.8.3.2
2013-08-04 00:51:09 +02:00