2015-07-27 12:20:54 +00:00
|
|
|
From 426206c162bab9cdffb452562b8ec8f608e76655 Mon Sep 17 00:00:00 2001
|
2014-07-21 20:46:54 +00:00
|
|
|
From: md_5 <md_5@live.com.au>
|
|
|
|
Date: Tue, 11 Jun 2013 12:56:02 +1000
|
|
|
|
Subject: [PATCH] Better Chunk Tick Selection
|
|
|
|
|
|
|
|
An optimized chunk ticking algorithm which better selects chunks around players which are active on the server.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2015-07-27 12:20:54 +00:00
|
|
|
index 1638081..5cb66a5 100644
|
2014-07-21 20:46:54 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2015-03-16 10:19:21 +00:00
|
|
|
@@ -68,7 +68,7 @@ public abstract class World implements IBlockAccess {
|
2015-02-28 11:36:22 +00:00
|
|
|
public Scoreboard scoreboard = new Scoreboard(); // CraftBukkit - public
|
|
|
|
public final boolean isClientSide;
|
2014-11-28 01:17:45 +00:00
|
|
|
// CraftBukkit - longhashset
|
2014-07-21 20:46:54 +00:00
|
|
|
- protected LongHashSet chunkTickList = new LongHashSet();
|
|
|
|
+ // protected LongHashSet chunkTickList = new LongHashSet(); // Spigot
|
2015-02-28 11:36:22 +00:00
|
|
|
private int L;
|
|
|
|
public boolean allowMonsters; // CraftBukkit - public
|
|
|
|
public boolean allowAnimals; // CraftBukkit - public
|
2015-03-16 10:19:21 +00:00
|
|
|
@@ -102,6 +102,31 @@ public abstract class World implements IBlockAccess {
|
2014-11-28 01:17:45 +00:00
|
|
|
public long ticksPerMonsterSpawns;
|
|
|
|
public boolean populating;
|
|
|
|
private int tickPosition;
|
|
|
|
+
|
2014-07-21 20:46:54 +00:00
|
|
|
+ // Spigot start
|
2014-11-28 01:17:45 +00:00
|
|
|
+ protected final gnu.trove.map.hash.TLongShortHashMap chunkTickList;
|
2014-07-21 20:46:54 +00:00
|
|
|
+ protected float growthOdds = 100;
|
|
|
|
+ protected float modifiedOdds = 100;
|
|
|
|
+ private final byte chunkTickRadius;
|
|
|
|
+
|
|
|
|
+ public static long chunkToKey(int x, int z)
|
|
|
|
+ {
|
|
|
|
+ long k = ( ( ( (long) x ) & 0xFFFF0000L ) << 16 ) | ( ( ( (long) x ) & 0x0000FFFFL ) << 0 );
|
2014-11-28 01:17:45 +00:00
|
|
|
+ k |= ( ( ( (long) z ) & 0xFFFF0000L ) << 32 ) | ( ( ( (long) z ) & 0x0000FFFFL ) << 16 );
|
2014-07-21 20:46:54 +00:00
|
|
|
+ return k;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static int keyToX(long k)
|
|
|
|
+ {
|
|
|
|
+ return (int) ( ( ( k >> 16 ) & 0xFFFF0000 ) | ( k & 0x0000FFFF ) );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static int keyToZ(long k)
|
|
|
|
+ {
|
|
|
|
+ return (int) ( ( ( k >> 32 ) & 0xFFFF0000L ) | ( ( k >> 16 ) & 0x0000FFFF ) );
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
+
|
2014-11-28 01:17:45 +00:00
|
|
|
public final org.spigotmc.SpigotWorldConfig spigotConfig; // Spigot
|
|
|
|
|
|
|
|
public CraftWorld getWorld() {
|
2015-03-16 10:19:21 +00:00
|
|
|
@@ -123,6 +148,12 @@ public abstract class World implements IBlockAccess {
|
2014-07-21 20:46:54 +00:00
|
|
|
this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit
|
|
|
|
this.ticksPerMonsterSpawns = this.getServer().getTicksPerMonsterSpawns(); // CraftBukkit
|
|
|
|
// CraftBukkit end
|
|
|
|
+ // Spigot start
|
|
|
|
+ this.chunkTickRadius = (byte) ( ( this.getServer().getViewDistance() < 7 ) ? this.getServer().getViewDistance() : 7 );
|
2014-11-28 01:17:45 +00:00
|
|
|
+ this.chunkTickList = new gnu.trove.map.hash.TLongShortHashMap( spigotConfig.chunksPerTick * 5, 0.7f, Long.MIN_VALUE, Short.MIN_VALUE );
|
2014-07-21 20:46:54 +00:00
|
|
|
+ this.chunkTickList.setAutoCompactionFactor( 0 );
|
|
|
|
+ // Spigot end
|
2015-02-28 11:36:22 +00:00
|
|
|
+
|
|
|
|
this.L = this.random.nextInt(12000);
|
2014-07-21 20:46:54 +00:00
|
|
|
this.allowMonsters = true;
|
2015-02-28 11:36:22 +00:00
|
|
|
this.allowAnimals = true;
|
2015-06-01 07:06:20 +00:00
|
|
|
@@ -1964,18 +1995,43 @@ public abstract class World implements IBlockAccess {
|
2014-07-21 20:46:54 +00:00
|
|
|
int k;
|
|
|
|
int l;
|
|
|
|
|
|
|
|
+ // Spigot start
|
|
|
|
+ int optimalChunks = spigotConfig.chunksPerTick;
|
|
|
|
+ // Quick conditions to allow us to exist early
|
2015-06-01 07:06:20 +00:00
|
|
|
+ if ( optimalChunks > 0 ) {
|
2014-07-21 20:46:54 +00:00
|
|
|
+ // Keep chunks with growth inside of the optimal chunk range
|
|
|
|
+ int chunksPerPlayer = Math.min( 200, Math.max( 1, (int) ( ( ( optimalChunks - players.size() ) / (double) players.size() ) + 0.5 ) ) );
|
|
|
|
+ int randRange = 3 + chunksPerPlayer / 30;
|
|
|
|
+ // Limit to normal tick radius - including view distance
|
|
|
|
+ randRange = ( randRange > chunkTickRadius ) ? chunkTickRadius : randRange;
|
|
|
|
+ // odds of growth happening vs growth happening in vanilla
|
|
|
|
+ this.growthOdds = this.modifiedOdds = Math.max( 35, Math.min( 100, ( ( chunksPerPlayer + 1 ) * 100F ) / 15F ) );
|
|
|
|
+ // Spigot end
|
|
|
|
for (i = 0; i < this.players.size(); ++i) {
|
|
|
|
entityhuman = (EntityHuman) this.players.get(i);
|
|
|
|
j = MathHelper.floor(entityhuman.locX / 16.0D);
|
|
|
|
k = MathHelper.floor(entityhuman.locZ / 16.0D);
|
2014-11-28 01:17:45 +00:00
|
|
|
l = this.q();
|
2014-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
- for (int i1 = -l; i1 <= l; ++i1) {
|
|
|
|
- for (int j1 = -l; j1 <= l; ++j1) {
|
2014-11-28 01:17:45 +00:00
|
|
|
- this.chunkTickList.add(org.bukkit.craftbukkit.util.LongHash.toLong(i1 + j, j1 + k));
|
2014-07-21 20:46:54 +00:00
|
|
|
+ // Spigot start - Always update the chunk the player is on
|
|
|
|
+ long key = chunkToKey( j, k );
|
|
|
|
+ int existingPlayers = Math.max( 0, chunkTickList.get( key ) ); // filter out -1
|
2014-11-28 01:17:45 +00:00
|
|
|
+ chunkTickList.put( key, (short) ( existingPlayers + 1 ) );
|
2014-07-21 20:46:54 +00:00
|
|
|
+
|
|
|
|
+ // Check and see if we update the chunks surrounding the player this tick
|
|
|
|
+ for ( int chunk = 0; chunk < chunksPerPlayer; chunk++ )
|
|
|
|
+ {
|
|
|
|
+ int dx = ( random.nextBoolean() ? 1 : -1 ) * random.nextInt( randRange );
|
|
|
|
+ int dz = ( random.nextBoolean() ? 1 : -1 ) * random.nextInt( randRange );
|
|
|
|
+ long hash = chunkToKey( dx + j, dz + k );
|
2014-11-28 01:17:45 +00:00
|
|
|
+ if ( !chunkTickList.contains( hash ) && this.chunkProvider.isChunkLoaded(dx + j, dz + k ) )
|
2014-07-21 20:46:54 +00:00
|
|
|
+ {
|
|
|
|
+ chunkTickList.put( hash, (short) -1 ); // no players
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-01 07:06:20 +00:00
|
|
|
+ // Spigot End
|
|
|
|
+ }
|
2014-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
this.methodProfiler.b();
|
2015-06-01 07:06:20 +00:00
|
|
|
if (this.L > 0) {
|
2014-07-21 20:46:54 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
2015-07-27 12:20:54 +00:00
|
|
|
index d27aa67..690e7dc 100644
|
2014-07-21 20:46:54 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
2015-04-16 10:19:45 +00:00
|
|
|
@@ -357,12 +357,15 @@ public class WorldServer extends World implements IAsyncTaskHandler {
|
2014-11-28 01:17:45 +00:00
|
|
|
protected void h() {
|
|
|
|
super.h();
|
|
|
|
if (this.worldData.getType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
|
|
|
|
- Iterator iterator = this.chunkTickList.iterator();
|
|
|
|
+ // Spigot start
|
|
|
|
+ gnu.trove.iterator.TLongShortIterator iterator = this.chunkTickList.iterator();
|
2014-07-21 20:46:54 +00:00
|
|
|
|
2014-11-28 01:17:45 +00:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
- ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next();
|
|
|
|
+ iterator.advance();
|
|
|
|
+ long chunkCoord = iterator.key();
|
2014-07-21 20:46:54 +00:00
|
|
|
|
2014-11-28 01:17:45 +00:00
|
|
|
- this.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z).b(false);
|
|
|
|
+ this.getChunkAt(World.keyToX( chunkCoord ), World.keyToZ( chunkCoord )).b(false);
|
|
|
|
+ // Spigot end
|
|
|
|
}
|
2014-07-21 20:46:54 +00:00
|
|
|
|
2014-11-28 01:17:45 +00:00
|
|
|
} else {
|
2015-04-16 10:19:45 +00:00
|
|
|
@@ -374,9 +377,21 @@ public class WorldServer extends World implements IAsyncTaskHandler {
|
2014-11-28 01:17:45 +00:00
|
|
|
// ChunkCoordIntPair chunkcoordintpair1 = (ChunkCoordIntPair) iterator1.next();
|
|
|
|
// int k = chunkcoordintpair1.x * 16;
|
|
|
|
// int l = chunkcoordintpair1.z * 16;
|
|
|
|
- for (long chunkCoord : chunkTickList.popAll()) {
|
|
|
|
- int chunkX = LongHash.msw(chunkCoord);
|
|
|
|
- int chunkZ = LongHash.lsw(chunkCoord);
|
|
|
|
+ // Spigot start
|
|
|
|
+ for (gnu.trove.iterator.TLongShortIterator iter = chunkTickList.iterator(); iter.hasNext(); )
|
|
|
|
+ {
|
|
|
|
+ iter.advance();
|
|
|
|
+ long chunkCoord = iter.key();
|
|
|
|
+ int chunkX = World.keyToX( chunkCoord );
|
|
|
|
+ int chunkZ = World.keyToZ( chunkCoord );
|
|
|
|
+ // If unloaded, or in procedd of being unloaded, drop it
|
|
|
|
+ if ( ( !this.chunkProvider.isChunkLoaded( chunkX, chunkZ ) ) || ( this.chunkProviderServer.unloadQueue.contains( chunkX, chunkZ ) ) )
|
|
|
|
+ {
|
|
|
|
+ iter.remove();
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
+ // ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next();
|
|
|
|
int k = chunkX * 16;
|
|
|
|
int l = chunkZ * 16;
|
2015-02-28 11:36:22 +00:00
|
|
|
|
2015-04-16 10:19:45 +00:00
|
|
|
@@ -470,6 +485,12 @@ public class WorldServer extends World implements IAsyncTaskHandler {
|
2014-11-28 01:17:45 +00:00
|
|
|
}
|
2014-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
+ // Spigot Start
|
|
|
|
+ if ( spigotConfig.clearChunksOnTick )
|
|
|
|
+ {
|
|
|
|
+ chunkTickList.clear();
|
|
|
|
+ }
|
|
|
|
+ // Spigot End
|
|
|
|
}
|
|
|
|
|
2014-11-28 01:17:45 +00:00
|
|
|
protected BlockPosition a(BlockPosition blockposition) {
|
2014-07-21 20:46:54 +00:00
|
|
|
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
|
|
index 961ddb4..90a227f 100644
|
|
|
|
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
|
|
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
|
|
@@ -68,4 +68,15 @@ public class SpigotWorldConfig
|
|
|
|
config.addDefault( "world-settings.default." + path, def );
|
|
|
|
return config.getString( "world-settings." + worldName + "." + path, config.getString( "world-settings.default." + path ) );
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public int chunksPerTick;
|
|
|
|
+ public boolean clearChunksOnTick;
|
|
|
|
+ private void chunksPerTick()
|
|
|
|
+ {
|
|
|
|
+ chunksPerTick = getInt( "chunks-per-tick", 650 );
|
|
|
|
+ log( "Chunks to Grow per Tick: " + chunksPerTick );
|
|
|
|
+
|
|
|
|
+ clearChunksOnTick = getBoolean( "clear-tick-list", false );
|
|
|
|
+ log( "Clear tick list: " + clearChunksOnTick );
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
--
|
2015-05-25 12:05:40 +00:00
|
|
|
2.1.4
|
2014-07-21 20:46:54 +00:00
|
|
|
|