diff options
author | Tahg <tahgtahv@gmail.com> | 2011-12-06 08:52:45 -0500 |
---|---|---|
committer | Tahg <tahgtahv@gmail.com> | 2011-12-06 08:52:45 -0500 |
commit | bc8f02788f37af0f03c9672903595b2f2f57d161 (patch) | |
tree | 4ea558b2192978679fbc5f91f53967b1b7a0c8d7 /src/main/java/net/minecraft | |
parent | eead44a6929a3de6068e2b81185013e1c6ee033f (diff) | |
download | craftbukkit-bc8f02788f37af0f03c9672903595b2f2f57d161.tar craftbukkit-bc8f02788f37af0f03c9672903595b2f2f57d161.tar.gz craftbukkit-bc8f02788f37af0f03c9672903595b2f2f57d161.tar.lz craftbukkit-bc8f02788f37af0f03c9672903595b2f2f57d161.tar.xz craftbukkit-bc8f02788f37af0f03c9672903595b2f2f57d161.zip |
Performance update to remove several very high counts of temp object creation
Diffstat (limited to 'src/main/java/net/minecraft')
5 files changed, 59 insertions, 29 deletions
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index aa11ced1..e09b519e 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -175,7 +175,9 @@ public abstract class EntityLiving extends Entity { this.extinguish(); } else { - this.setAirTicks(maxAirTicks); // CraftBukkit - update maxAirTicks if no longer 300 + if (this.getAirTicks() != 300) { + this.setAirTicks(maxAirTicks); + } } this.aw = this.ax; diff --git a/src/main/java/net/minecraft/server/EntityTracker.java b/src/main/java/net/minecraft/server/EntityTracker.java index a1bd3224..37a5cd15 100644 --- a/src/main/java/net/minecraft/server/EntityTracker.java +++ b/src/main/java/net/minecraft/server/EntityTracker.java @@ -11,9 +11,9 @@ public class EntityTracker { private IntHashMap trackedEntities = new IntHashMap(); private MinecraftServer c; private int d; - private int e; + private World e; // CraftBukkit - change type - public EntityTracker(MinecraftServer minecraftserver, int i) { + public EntityTracker(MinecraftServer minecraftserver, World i) { // CraftBukkit - change method signature this.c = minecraftserver; this.e = i; this.d = minecraftserver.serverConfigurationManager.a(); @@ -94,7 +94,7 @@ public class EntityTracker { this.a.add(entitytrackerentry); this.trackedEntities.a(entity.id, entitytrackerentry); - entitytrackerentry.scanPlayers(this.c.getWorldServer(this.e).players); + entitytrackerentry.scanPlayers(this.e.players); // CraftBukkit } } @@ -127,7 +127,7 @@ public class EntityTracker { while (iterator.hasNext()) { EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next(); - entitytrackerentry.track(this.c.getWorldServer(this.e).players); + entitytrackerentry.track(this.e.players); // CraftBukkit if (entitytrackerentry.m && entitytrackerentry.tracker instanceof EntityPlayer) { arraylist.add((EntityPlayer) entitytrackerentry.tracker); } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index d8ae5274..cea2ffb2 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -267,7 +267,7 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe this.server.getPluginManager().callEvent(new WorldInitEvent(world.getWorld())); - world.tracker = new EntityTracker(this, dimension); + world.tracker = new EntityTracker(this, world); // CraftBukkit world.addIWorldAccess(new WorldManager(this, world)); world.difficulty = this.propertyManager.getInt("difficulty", 1); world.setSpawnFlags(this.propertyManager.getBoolean("spawn-monsters", true), this.spawnAnimals); diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java index 28a8b03a..bbb64f05 100644 --- a/src/main/java/net/minecraft/server/SpawnerCreature.java +++ b/src/main/java/net/minecraft/server/SpawnerCreature.java @@ -1,5 +1,6 @@ package net.minecraft.server; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -7,11 +8,28 @@ import java.util.List; import java.util.Random; // CraftBukkit +import org.bukkit.craftbukkit.util.LongAbstractHashtable; +import org.bukkit.craftbukkit.util.EntryBase; +import org.bukkit.craftbukkit.util.LongHash; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; public final class SpawnerCreature { - private static HashMap b = new HashMap(); + // private static HashMap b = new HashMap(); // CraftBukkit -- moved local to spawnEntities + static private class ChunkEntry extends EntryBase { + public boolean spawn; + public ChunkEntry (int x, int z, boolean spawn) { + super(LongHash.toLong(x, z)); + this.spawn = spawn; + } + int getX() { + return LongHash.msw(key); + } + int getZ() { + return LongHash.lsw(key); + } + } + protected static final Class[] a = new Class[] { EntitySpider.class, EntityZombie.class, EntitySkeleton.class}; public SpawnerCreature() {} @@ -28,7 +46,9 @@ public final class SpawnerCreature { if (!flag && !flag1) { return 0; } else { - b.clear(); + // b.clear(); // CraftBukkit + LongAbstractHashtable chunkCoords; // CraftBukkit + chunkCoords = new LongAbstractHashtable() {}; int i; int j; @@ -43,19 +63,22 @@ public final class SpawnerCreature { for (int l = -b0; l <= b0; ++l) { for (int i1 = -b0; i1 <= b0; ++i1) { boolean flag2 = l == -b0 || l == b0 || i1 == -b0 || i1 == b0; - ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(l + k, i1 + j); + // CraftBukkit start + long chunkCoord = LongHash.toLong(l + k, i1 + j); if (!flag2) { - b.put(chunkcoordintpair, Boolean.valueOf(false)); - } else if (!b.containsKey(chunkcoordintpair)) { - b.put(chunkcoordintpair, Boolean.valueOf(true)); + chunkCoords.put(new ChunkEntry(l + k, i1 + j, false)); + } else if (!chunkCoords.containsKey(chunkCoord)) { + chunkCoords.put(new ChunkEntry(l + k, i1 + j, true)); } + // CraftBukkit end } } } i = 0; ChunkCoordinates chunkcoordinates = world.getSpawn(); + ArrayList<EntryBase> entries = chunkCoords.entries(); // CraftBukkit EnumCreatureType[] aenumcreaturetype = EnumCreatureType.values(); j = aenumcreaturetype.length; @@ -63,15 +86,14 @@ public final class SpawnerCreature { for (int j1 = 0; j1 < j; ++j1) { EnumCreatureType enumcreaturetype = aenumcreaturetype[j1]; - if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && world.a(enumcreaturetype.a()) <= enumcreaturetype.b() * b.size() / 256) { - Iterator iterator = b.keySet().iterator(); - label108: - while (iterator.hasNext()) { - ChunkCoordIntPair chunkcoordintpair1 = (ChunkCoordIntPair) iterator.next(); + if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && world.a(enumcreaturetype.a()) <= enumcreaturetype.b() * entries.size() / 256) { - if (!((Boolean) b.get(chunkcoordintpair1)).booleanValue()) { - ChunkPosition chunkposition = a(world, chunkcoordintpair1.x * 16, chunkcoordintpair1.z * 16); + label108: + for (EntryBase base : entries) { + ChunkEntry entry = (SpawnerCreature.ChunkEntry) base; + if (!entry.spawn) { + ChunkPosition chunkposition = a(world, LongHash.msw(entry.getX()) * 16, entry.getZ() * 16); int k1 = chunkposition.x; int l1 = chunkposition.y; int i2 = chunkposition.z; diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index 805bb210..ea939f86 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -14,6 +14,8 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.craftbukkit.util.LongHash; +import org.bukkit.craftbukkit.util.LongHashset; import org.bukkit.generator.ChunkGenerator; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; @@ -74,7 +76,7 @@ public class World implements IBlockAccess { private boolean S; public boolean allowMonsters; // CraftBukkit - private -> public public boolean allowAnimals; // CraftBukkit - private -> public - private Set T; + private LongHashset T; // CraftBukkit private int U; int[] H; private List V; @@ -145,7 +147,7 @@ public class World implements IBlockAccess { this.R = new ArrayList(); this.allowMonsters = true; this.allowAnimals = true; - this.T = new HashSet(); + this.T = new LongHashset(); // CraftBukkit this.U = this.random.nextInt(12000); this.H = new int['\u8000']; this.V = new ArrayList(); @@ -1856,7 +1858,7 @@ public class World implements IBlockAccess { } protected void k() { - this.T.clear(); + // this.T.clear(); // CraftBukkit -- removed // MethodProfiler.a("buildList"); // CraftBukkit -- not in production code int i; @@ -1870,7 +1872,7 @@ public class World implements IBlockAccess { for (j = -b0; j <= b0; ++j) { for (int i1 = -b0; i1 <= b0; ++i1) { - this.T.add(new ChunkCoordIntPair(j + k, i1 + l)); + this.T.add(LongHash.toLong(j + k, i1 + l)); // CraftBukkit } } } @@ -1883,15 +1885,19 @@ public class World implements IBlockAccess { int j1 = 0; // MethodProfiler.a(); // CraftBukkit -- not in production code - Iterator iterator = this.T.iterator(); + // Iterator iterator = this.T.iterator(); CraftBukkit == removed - while (iterator.hasNext()) { - ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next(); - int k1 = chunkcoordintpair.x * 16; + // CraftBukkit start + for (long chunkCoord : this.T.popAll()) { + int chunkX = LongHash.msw(chunkCoord); + int chunkZ = LongHash.lsw(chunkCoord); + // ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next(); + int k1 = chunkX * 16; - j = chunkcoordintpair.z * 16; + j = chunkZ * 16; // MethodProfiler.a("getChunk"); // CraftBukkit -- not in production code - Chunk chunk = this.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z); + Chunk chunk = this.getChunkAt(chunkX, chunkZ); + // CraftBukkit end // MethodProfiler.b("tickChunk"); // CraftBukkit -- not in production code chunk.i(); |