diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2014-06-16 19:01:55 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2014-06-21 21:12:46 -0500 |
commit | 5b9950b5f7f4143323c0edced82fce269d5e5ddc (patch) | |
tree | 999f04a0910a2e304a390e47b084251cea1af7d8 /src/main/java/net/minecraft/server/ChunkProviderServer.java | |
parent | ea126f98adfb3a54c1b0defb262ff583127b52b3 (diff) | |
download | craftbukkit-5b9950b5f7f4143323c0edced82fce269d5e5ddc.tar craftbukkit-5b9950b5f7f4143323c0edced82fce269d5e5ddc.tar.gz craftbukkit-5b9950b5f7f4143323c0edced82fce269d5e5ddc.tar.lz craftbukkit-5b9950b5f7f4143323c0edced82fce269d5e5ddc.tar.xz craftbukkit-5b9950b5f7f4143323c0edced82fce269d5e5ddc.zip |
Avoid checking for loaded chunks for lighting and entity ticking.
When a chunk is loaded the server tries to ensure it has its initial light
calculations done before sending it to the player. When ticking entities
the server tries to ensure the entity does not walk into an unloaded chunk.
To accomplish these the server checks a one chunk radius around the chunk
to be lit or a two chunk radius around the chunk the entity is in. These
lookups happen every tick even though their result is unlikely to change
that often. To reduce the cost of these checks we replace them with a
system to keep track of what neighbor chunks a chunk has loaded and update
it when chunks load or unload which is a much less frequent action. On a
server with ten players this change removes about 100,000 calls a tick to
LongObjectHashMap's containsKey method.
Diffstat (limited to 'src/main/java/net/minecraft/server/ChunkProviderServer.java')
-rw-r--r-- | src/main/java/net/minecraft/server/ChunkProviderServer.java | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java index 1b22934d..8cc2efd4 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -94,6 +94,10 @@ public class ChunkProviderServer implements IChunkProvider { } // CraftBukkit start - Add async variant, provide compatibility + public Chunk getChunkIfLoaded(int x, int z) { + return this.chunks.get(LongHash.toLong(x, z)); + } + public Chunk getChunkAt(int i, int j) { return getChunkAt(i, j, null); } @@ -166,6 +170,21 @@ public class ChunkProviderServer implements IChunkProvider { */ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(chunk.bukkitChunk, newChunk)); } + + // Update neighbor counts + for (int x = -2; x < 3; x++) { + for (int z = -2; z < 3; z++) { + if (x == 0 && z == 0) { + continue; + } + + Chunk neighbor = this.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z); + if (neighbor != null) { + neighbor.setNeighborLoaded(-x, -z); + chunk.setNeighborLoaded(x, z); + } + } + } // CraftBukkit end chunk.a(this, this, i, j); } @@ -327,6 +346,21 @@ public class ChunkProviderServer implements IChunkProvider { // this.unloadQueue.remove(olong); // this.chunks.remove(olong.longValue()); + + // Update neighbor counts + for (int x = -2; x < 3; x++) { + for (int z = -2; z < 3; z++) { + if (x == 0 && z == 0) { + continue; + } + + Chunk neighbor = this.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z); + if (neighbor != null) { + neighbor.setNeighborUnloaded(-x, -z); + chunk.setNeighborUnloaded(x, z); + } + } + } } } // CraftBukkit end @@ -357,8 +391,8 @@ public class ChunkProviderServer implements IChunkProvider { } public int getLoadedChunks() { - // CraftBukkit - this.chunks.count() -> .values().size() - return this.chunks.values().size(); + // CraftBukkit - this.chunks.count() -> this.chunks.size() + return this.chunks.size(); } public void recreateStructures(int i, int j) {} |