2014-03-23 01:06:43 +01:00
|
|
|
From 8fe65d8a9c999b2ebca1f63634de6a03d83d2f39 Mon Sep 17 00:00:00 2001
|
2013-06-11 04:56:24 +02:00
|
|
|
From: md_5 <md_5@live.com.au>
|
|
|
|
Date: Tue, 11 Jun 2013 12:56:02 +1000
|
|
|
|
Subject: [PATCH] Better Chunk Tick Selection
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2014-03-23 01:06:43 +01:00
|
|
|
index 96a3eb8..9dc2d73 100644
|
2013-06-11 04:56:24 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2014-03-23 01:06:43 +01:00
|
|
|
@@ -60,7 +60,7 @@ public abstract class World implements IBlockAccess {
|
2013-12-01 05:13:58 +01:00
|
|
|
public Scoreboard scoreboard = new Scoreboard(); // CraftBukkit - protected -> public
|
|
|
|
public boolean isStatic;
|
|
|
|
// CraftBukkit start - public, longhashset
|
|
|
|
- protected LongHashSet chunkTickList = new LongHashSet();
|
|
|
|
+ // protected LongHashSet chunkTickList = new LongHashSet(); // Spigot
|
2014-03-23 01:06:43 +01:00
|
|
|
private int K;
|
2013-12-01 05:13:58 +01:00
|
|
|
public boolean allowMonsters;
|
|
|
|
public boolean allowAnimals;
|
2014-03-23 01:06:43 +01:00
|
|
|
@@ -75,6 +75,30 @@ public abstract class World implements IBlockAccess {
|
|
|
|
private boolean M;
|
2013-12-01 04:40:53 +01:00
|
|
|
int[] I;
|
|
|
|
|
2013-06-11 04:56:24 +02:00
|
|
|
+ // Spigot start
|
|
|
|
+ protected final gnu.trove.map.hash.TLongShortHashMap chunkTickList;
|
|
|
|
+ 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 );
|
|
|
|
+ k |= ( ( ( (long) z ) & 0xFFFF0000L ) << 32 ) | ( ( ( (long) z ) & 0x0000FFFFL ) << 16 );
|
|
|
|
+ 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
|
2013-12-01 04:40:53 +01:00
|
|
|
+
|
2013-06-11 04:56:24 +02:00
|
|
|
public BiomeBase getBiome(int i, int j) {
|
|
|
|
if (this.isLoaded(i, 0, j)) {
|
2013-12-01 04:40:53 +01:00
|
|
|
Chunk chunk = this.getChunkAtWorldCoords(i, j);
|
2014-03-23 01:06:43 +01:00
|
|
|
@@ -124,6 +148,11 @@ public abstract class World implements IBlockAccess {
|
2013-06-11 04:56:24 +02: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 );
|
2013-06-20 09:52:17 +02:00
|
|
|
+ this.chunkTickList = new gnu.trove.map.hash.TLongShortHashMap( spigotConfig.chunksPerTick * 5, 0.7f, Long.MIN_VALUE, Short.MIN_VALUE );
|
2013-06-11 04:56:24 +02:00
|
|
|
+ this.chunkTickList.setAutoCompactionFactor( 0 );
|
|
|
|
+ // Spigot end
|
|
|
|
|
2014-03-23 01:06:43 +01:00
|
|
|
this.K = this.random.nextInt(12000);
|
2013-12-01 04:40:53 +01:00
|
|
|
this.allowMonsters = true;
|
2014-03-23 01:06:43 +01:00
|
|
|
@@ -1914,24 +1943,44 @@ public abstract class World implements IBlockAccess {
|
2013-06-11 04:56:24 +02:00
|
|
|
int k;
|
2014-03-23 01:06:43 +01:00
|
|
|
int l;
|
2013-06-11 04:56:24 +02:00
|
|
|
|
|
|
|
+ // Spigot start
|
2013-06-20 09:52:17 +02:00
|
|
|
+ int optimalChunks = spigotConfig.chunksPerTick;
|
2013-06-11 04:56:24 +02:00
|
|
|
+ // Quick conditions to allow us to exist early
|
|
|
|
+ if ( optimalChunks <= 0 || players.isEmpty() )
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 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-03-23 01:06:43 +01:00
|
|
|
l = this.p();
|
2013-06-11 04:56:24 +02:00
|
|
|
|
2014-03-23 01:06:43 +01:00
|
|
|
- for (int i1 = -l; i1 <= l; ++i1) {
|
|
|
|
- for (int j1 = -l; j1 <= l; ++j1) {
|
2013-06-11 04:56:24 +02:00
|
|
|
- // CraftBukkit start - Don't tick chunks queued for unload
|
|
|
|
- ChunkProviderServer chunkProviderServer = ((WorldServer) entityhuman.world).chunkProviderServer;
|
2014-03-23 01:06:43 +01:00
|
|
|
- if (chunkProviderServer.unloadQueue.contains(i1 + j, j1 + k)) {
|
2013-06-11 04:56:24 +02:00
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- // CraftBukkit end
|
|
|
|
-
|
2014-03-23 01:06:43 +01:00
|
|
|
- this.chunkTickList.add(org.bukkit.craftbukkit.util.LongHash.toLong(i1 + j, j1 + k)); // CraftBukkit
|
2013-06-11 04:56:24 +02: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
|
|
|
|
+ chunkTickList.put(key, (short) (existingPlayers + 1));
|
|
|
|
+
|
|
|
|
+ // 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 );
|
|
|
|
+ if ( !chunkTickList.contains( hash ) && this.isChunkLoaded( dx + j, dz + k ) )
|
|
|
|
+ {
|
|
|
|
+ chunkTickList.put( hash, (short) -1 ); // no players
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // Spigot End
|
|
|
|
}
|
|
|
|
|
|
|
|
this.methodProfiler.b();
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
2014-03-23 01:06:43 +01:00
|
|
|
index 4e0861e..acb0be1 100644
|
2013-06-11 04:56:24 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
2013-12-01 04:40:53 +01:00
|
|
|
@@ -306,10 +306,20 @@ public class WorldServer extends World implements org.bukkit.BlockChangeDelegate
|
2013-06-11 04:56:24 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
// Iterator iterator = this.chunkTickList.iterator();
|
|
|
|
|
|
|
|
- for (long chunkCoord : this.chunkTickList.popAll()) {
|
|
|
|
+ // 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.isChunkLoaded( chunkX, chunkZ ) ) || ( this.chunkProviderServer.unloadQueue.contains( chunkX, chunkZ ) ) )
|
|
|
|
+ {
|
|
|
|
+ iter.remove();
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
// ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next();
|
2013-12-01 04:40:53 +01:00
|
|
|
- int chunkX = LongHash.msw(chunkCoord);
|
|
|
|
- int chunkZ = LongHash.lsw(chunkCoord);
|
2013-06-11 04:56:24 +02:00
|
|
|
int k = chunkX * 16;
|
|
|
|
int l = chunkZ * 16;
|
2013-12-01 04:40:53 +01:00
|
|
|
|
2013-07-02 05:03:56 +02:00
|
|
|
@@ -400,6 +410,7 @@ public class WorldServer extends World implements org.bukkit.BlockChangeDelegate
|
2013-06-11 04:56:24 +02:00
|
|
|
|
2013-12-01 04:40:53 +01:00
|
|
|
if (block.isTicking()) {
|
2013-06-11 04:56:24 +02:00
|
|
|
++i;
|
|
|
|
+ this.growthOdds = (iter.value() < 1) ? this.modifiedOdds : 100; // Spigot - grow fast if no players are in this chunk (value = player count)
|
|
|
|
block.a(this, k2 + k, i3 + chunksection.getYPosition(), l2 + l, this.random);
|
|
|
|
}
|
|
|
|
}
|
2014-01-14 09:16:43 +01:00
|
|
|
@@ -408,6 +419,12 @@ public class WorldServer extends World implements org.bukkit.BlockChangeDelegate
|
2014-01-08 04:38:38 +01:00
|
|
|
|
|
|
|
this.methodProfiler.b();
|
|
|
|
}
|
2014-01-14 09:16:43 +01:00
|
|
|
+ // Spigot Start
|
|
|
|
+ if ( spigotConfig.clearChunksOnTick )
|
|
|
|
+ {
|
|
|
|
+ chunkTickList.clear();
|
|
|
|
+ }
|
|
|
|
+ // Spigot End
|
2014-01-08 04:38:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(int i, int j, int k, Block block) {
|
2013-06-20 09:52:17 +02:00
|
|
|
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
2014-03-09 23:14:45 +01:00
|
|
|
index 961ddb4..90a227f 100644
|
2013-06-20 09:52:17 +02:00
|
|
|
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
|
|
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
2014-01-14 09:16:43 +01:00
|
|
|
@@ -68,4 +68,15 @@ public class SpigotWorldConfig
|
2013-06-20 09:52:17 +02:00
|
|
|
config.addDefault( "world-settings.default." + path, def );
|
|
|
|
return config.getString( "world-settings." + worldName + "." + path, config.getString( "world-settings.default." + path ) );
|
|
|
|
}
|
2013-06-15 14:01:15 +02:00
|
|
|
+
|
2013-06-21 09:00:01 +02:00
|
|
|
+ public int chunksPerTick;
|
2014-01-14 09:16:43 +01:00
|
|
|
+ public boolean clearChunksOnTick;
|
2013-06-20 09:52:17 +02:00
|
|
|
+ private void chunksPerTick()
|
|
|
|
+ {
|
2013-06-21 09:00:01 +02:00
|
|
|
+ chunksPerTick = getInt( "chunks-per-tick", 650 );
|
2013-06-20 09:52:17 +02:00
|
|
|
+ log( "Chunks to Grow per Tick: " + chunksPerTick );
|
2014-01-14 09:16:43 +01:00
|
|
|
+
|
|
|
|
+ clearChunksOnTick = getBoolean( "clear-tick-list", false );
|
2014-02-18 03:44:13 +01:00
|
|
|
+ log( "Clear tick list: " + clearChunksOnTick );
|
2013-06-20 09:52:17 +02:00
|
|
|
+ }
|
|
|
|
}
|
2013-06-11 04:56:24 +02:00
|
|
|
--
|
2014-03-23 01:06:43 +01:00
|
|
|
1.8.5.2.msysgit.0
|
2013-06-11 04:56:24 +02:00
|
|
|
|