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.
This commit is contained in:
Travis Watkins committed 2014-06-21 21:12:46 -05:00
1 parent ea126f98ad
commit 5b9950b5f7
4 files changed
+92 -5

No files matched your search

+12 -2
View File
@@ -115,6 +115,10 @@ public abstract class World implements IBlockAccess {
return (CraftServer) Bukkit.getServer();
}
public Chunk getChunkIfLoaded(int x, int z) {
return ((ChunkProviderServer) this.chunkProvider).getChunkIfLoaded(x, z);
}
// Changed signature - added gen and env
public World(IDataManager idatamanager, String s, WorldSettings worldsettings, WorldProvider worldprovider, MethodProfiler methodprofiler, ChunkGenerator gen, org.bukkit.World.Environment env) {
this.generator = gen;
@@ -1396,7 +1400,10 @@ public abstract class World implements IBlockAccess {
int j = MathHelper.floor(entity.locZ);
byte b0 = 32;
if (!flag || this.b(i - b0, 0, j - b0, i + b0, 0, j + b0)) {
// CraftBukkit start - Use neighbor cache instead of looking up
Chunk startingChunk = this.getChunkIfLoaded(i >> 4, j >> 4);
if (!flag || (startingChunk != null && startingChunk.areNeighborsLoaded(2)) /* this.b(i - b0, 0, j - b0, i + b0, 0, j + b0) */) {
// CraftBukkit end
entity.S = entity.locX;
entity.T = entity.locY;
entity.U = entity.locZ;
@@ -2165,7 +2172,10 @@ public abstract class World implements IBlockAccess {
}
public boolean c(EnumSkyBlock enumskyblock, int i, int j, int k) {
if (!this.areChunksLoaded(i, j, k, 17)) {
// CraftBukkit start - Use neighbor cache instead of looking up
Chunk chunk = this.getChunkIfLoaded(i >> 4, k >> 4);
if (chunk == null || !chunk.areNeighborsLoaded(1) /* !this.areChunksLoaded(i, j, k, 17)*/) {
// CraftBukkit end
return false;
} else {
int l = 0;