From 713fe4fb2db2b2515336e16607ebac9fefa6eb4f Mon Sep 17 00:00:00 2001 From: Ammar Askar Date: Sat, 20 Apr 2013 13:50:09 +0500 Subject: [PATCH] Store creature counts to avoid repeated assignable checks and traversal of entity slices --- ...ts-for-randomly-spawned-creatures-to.patch | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 CraftBukkit-Patches/0040-Save-entity-counts-for-randomly-spawned-creatures-to.patch diff --git a/CraftBukkit-Patches/0040-Save-entity-counts-for-randomly-spawned-creatures-to.patch b/CraftBukkit-Patches/0040-Save-entity-counts-for-randomly-spawned-creatures-to.patch new file mode 100644 index 0000000000..8b1ff0e76f --- /dev/null +++ b/CraftBukkit-Patches/0040-Save-entity-counts-for-randomly-spawned-creatures-to.patch @@ -0,0 +1,83 @@ +From 42fcf69ddb25ec9aebbd6bbd45e552870b0373a9 Mon Sep 17 00:00:00 2001 +From: Ammar Askar +Date: Sat, 20 Apr 2013 12:26:20 +0500 +Subject: [PATCH] Save entity counts for randomly spawned creatures to avoid + repeatedly traversing over the entity slices + +--- + src/main/java/net/minecraft/server/Chunk.java | 16 ++++++++++++++++ + src/main/java/net/minecraft/server/SpawnerCreature.java | 10 ++-------- + 2 files changed, 18 insertions(+), 8 deletions(-) + +diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java +index 7f1c155..11e1a4e 100644 +--- a/src/main/java/net/minecraft/server/Chunk.java ++++ b/src/main/java/net/minecraft/server/Chunk.java +@@ -9,6 +9,7 @@ import java.util.Map; + import java.util.Random; + + import org.bukkit.Bukkit; // CraftBukkit ++import gnu.trove.map.hash.TObjectIntHashMap; // Spigot + + public class Chunk { + +@@ -33,6 +34,7 @@ public class Chunk { + public int p; + private int u; + boolean q; ++ protected TObjectIntHashMap entityCount = new TObjectIntHashMap(); // Spigot + + public Chunk(World world, int i, int j) { + this.sections = new ChunkSection[16]; +@@ -560,6 +562,13 @@ public class Chunk { + entity.ak = k; + entity.al = this.z; + this.entitySlices[k].add(entity); ++ // Spigot start - increment creature type count ++ for (EnumCreatureType creatureType : EnumCreatureType.values()) { ++ if (creatureType.a().isAssignableFrom(entity.getClass())) { ++ this.entityCount.adjustOrPutValue(creatureType.a(), 1, 1); ++ } ++ } ++ // Spigot end + } + + public void b(Entity entity) { +@@ -576,6 +585,13 @@ public class Chunk { + } + + this.entitySlices[i].remove(entity); ++ // Spigot start - decrement creature type count ++ for (EnumCreatureType creatureType : EnumCreatureType.values()) { ++ if (creatureType.a().isAssignableFrom(entity.getClass())) { ++ this.entityCount.adjustValue(creatureType.a(), -1); ++ } ++ } ++ // Spigot end + } + + public boolean d(int i, int j, int k) { +diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java +index 6362a37..2c3b94d 100644 +--- a/src/main/java/net/minecraft/server/SpawnerCreature.java ++++ b/src/main/java/net/minecraft/server/SpawnerCreature.java +@@ -33,14 +33,8 @@ public final class SpawnerCreature { + for (Long coord : b.keySet()) { + int x = LongHash.msw(coord); + int z = LongHash.lsw(coord); +- if (!server.chunkProviderServer.unloadQueue.contains(x,z) && server.isChunkLoaded(x, z)) { +- for (List entitySlice : server.getChunkAt(x, z).entitySlices) { +- for (Entity entity : entitySlice) { +- if (oClass.isAssignableFrom(entity.getClass())) { +- ++i; +- } +- } +- } ++ if (!server.chunkProviderServer.unloadQueue.contains(coord) && server.isChunkLoaded(x, z)) { ++ i += server.getChunkAt(x, z).entityCount.get(oClass); + } + } + return i; +-- +1.7.11.msysgit.0 +