3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 21:10:17 +01:00
Paper/CraftBukkit-Patches/0042-Entity-ticking-chunk-caching.patch

67 Zeilen
3.3 KiB
Diff

2014-04-24 08:27:12 +02:00
From 8b366c63f86ae90d9629fdd258d972ec64db1ff8 Mon Sep 17 00:00:00 2001
2014-04-12 06:18:37 +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
2014-04-24 08:27:12 +02:00
index ec4ce72..6da7de6 100644
2014-04-12 06:18:37 +02:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2014-04-24 08:27:12 +02:00
@@ -1263,6 +1263,7 @@ public abstract class World implements IBlockAccess {
2014-04-12 06:18:37 +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
2014-04-24 08:27:12 +02:00
@@ -1271,10 +1272,15 @@ public abstract class World implements IBlockAccess {
2014-04-12 06:18:37 +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;
2014-04-24 08:27:12 +02:00
@@ -1295,6 +1301,7 @@ public abstract class World implements IBlockAccess {
2014-04-12 06:18:37 +02:00
this.i.remove(i--);
}
}
+ lastChunk = Long.MIN_VALUE; // Spigot
this.methodProfiler.c("remove");
this.entityList.removeAll(this.f);
2014-04-24 08:27:12 +02:00
@@ -1326,10 +1333,15 @@ public abstract class World implements IBlockAccess {
2014-04-12 06:18:37 +02:00
// 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
if (entity.vehicle != null) {
if (!entity.vehicle.dead && entity.vehicle.passenger == entity) {
--
2014-04-19 01:15:23 +02:00
1.9.1
2014-04-12 06:18:37 +02:00