mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-06 10:49:40 +01:00
67 lines
3.3 KiB
Diff
67 lines
3.3 KiB
Diff
From 568c6c9068d74112aaae326208501a2dbd17ab82 Mon Sep 17 00:00:00 2001
|
|
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
|
|
index 7c66e3e..cbb4e77 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -1185,6 +1185,7 @@ public abstract class World implements IBlockAccess {
|
|
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
|
|
@@ -1193,10 +1194,15 @@ public abstract class World implements IBlockAccess {
|
|
}
|
|
|
|
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;
|
|
@@ -1217,6 +1223,7 @@ public abstract class World implements IBlockAccess {
|
|
this.i.remove(i--);
|
|
}
|
|
}
|
|
+ lastChunk = Long.MIN_VALUE; // Spigot
|
|
|
|
this.methodProfiler.c("remove");
|
|
this.entityList.removeAll(this.f);
|
|
@@ -1248,10 +1255,15 @@ public abstract class World implements IBlockAccess {
|
|
|
|
// 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) {
|
|
--
|
|
1.8.5.2.msysgit.0
|
|
|