aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0432-Optimize-anyPlayerCloseEnoughForSpawning-to-use-dist.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0432-Optimize-anyPlayerCloseEnoughForSpawning-to-use-dist.patch')
-rw-r--r--patches/server/0432-Optimize-anyPlayerCloseEnoughForSpawning-to-use-dist.patch44
1 files changed, 22 insertions, 22 deletions
diff --git a/patches/server/0432-Optimize-anyPlayerCloseEnoughForSpawning-to-use-dist.patch b/patches/server/0432-Optimize-anyPlayerCloseEnoughForSpawning-to-use-dist.patch
index 7a0006e19e..8665e32e6e 100644
--- a/patches/server/0432-Optimize-anyPlayerCloseEnoughForSpawning-to-use-dist.patch
+++ b/patches/server/0432-Optimize-anyPlayerCloseEnoughForSpawning-to-use-dist.patch
@@ -6,14 +6,14 @@ Subject: [PATCH] Optimize anyPlayerCloseEnoughForSpawning to use distance maps
Use a distance map to find the players in range quickly
diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java
-index b3dc875fde93095d20ae88159afe82c6b452ed8e..7c3eaa72263708f5b2cea455b3eea230bc633c5d 100644
+index 74d674b2684b0db4aa6c183edc6091d53e9ee882..626bcbc6dd013260c3f8b38a1d14e7ba35dc1e01 100644
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
@@ -73,6 +73,18 @@ public class ChunkHolder {
boolean isUpdateQueued = false; // Paper
private final ChunkMap chunkMap; // Paper
-+ // Paper start - optimise isOutsideOfRange
++ // Paper start - optimise anyPlayerCloseEnoughForSpawning
+ // cached here to avoid a map lookup
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> playersInMobSpawnRange;
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> playersInChunkTickRange;
@@ -23,7 +23,7 @@ index b3dc875fde93095d20ae88159afe82c6b452ed8e..7c3eaa72263708f5b2cea455b3eea230
+ this.playersInMobSpawnRange = this.chunkMap.playerMobSpawnMap.getObjectsInRange(key);
+ this.playersInChunkTickRange = this.chunkMap.playerChunkTickRangeMap.getObjectsInRange(key);
+ }
-+ // Paper end - optimise isOutsideOfRange
++ // Paper end - optimise anyPlayerCloseEnoughForSpawning
+
public ChunkHolder(ChunkPos pos, int level, LevelHeightAccessor world, LevelLightEngine lightingProvider, ChunkHolder.LevelChangeListener levelUpdateListener, ChunkHolder.PlayerProvider playersWatchingChunkProvider) {
this.futures = new AtomicReferenceArray(ChunkHolder.CHUNK_STATUSES.size());
@@ -32,19 +32,19 @@ index b3dc875fde93095d20ae88159afe82c6b452ed8e..7c3eaa72263708f5b2cea455b3eea230
this.setTicketLevel(level);
this.changedBlocksPerSection = new ShortSet[world.getSectionsCount()];
this.chunkMap = (ChunkMap)playersWatchingChunkProvider; // Paper
-+ this.updateRanges(); // Paper - optimise isOutsideOfRange
++ this.updateRanges(); // Paper - optimise anyPlayerCloseEnoughForSpawning
}
// CraftBukkit start
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
-index f4fddfcb33ae463c6a86e7282d069279258bc4ff..e64d1493c5e77daad2e410647412a2e1e9813109 100644
+index 4aa7672317dfd950495fa069f5e5b0f2aee21869..8e009c52070e0a939a479942d0ff4202f4463ad0 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -177,21 +177,40 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
final CallbackExecutor chunkLoadConversionCallbackExecutor = new CallbackExecutor(); // Paper
// Paper start - distance maps
private final com.destroystokyo.paper.util.misc.PooledLinkedHashSets<ServerPlayer> pooledLinkedPlayerHashSets = new com.destroystokyo.paper.util.misc.PooledLinkedHashSets<>();
-+ // Paper start - optimise PlayerChunkMap#isOutsideRange
++ // Paper start - optimise ChunkMap#anyPlayerCloseEnoughForSpawning
+ // A note about the naming used here:
+ // Previously, mojang used a "spawn range" of 8 for controlling both ticking and
+ // mob spawn range. However, spigot makes the spawn range configurable by
@@ -54,31 +54,31 @@ index f4fddfcb33ae463c6a86e7282d069279258bc4ff..e64d1493c5e77daad2e410647412a2e1
+ // these maps are named after spigot's uses
+ public final com.destroystokyo.paper.util.misc.PlayerAreaMap playerMobSpawnMap; // this map is absent from updateMaps since it's controlled at the start of the chunkproviderserver tick
+ public final com.destroystokyo.paper.util.misc.PlayerAreaMap playerChunkTickRangeMap;
-+ // Paper end - optimise PlayerChunkMap#isOutsideRange
++ // Paper end - optimise ChunkMap#anyPlayerCloseEnoughForSpawning
void addPlayerToDistanceMaps(ServerPlayer player) {
int chunkX = MCUtil.getChunkCoordinate(player.getX());
int chunkZ = MCUtil.getChunkCoordinate(player.getZ());
// Note: players need to be explicitly added to distance maps before they can be updated
-+ // Paper start - optimise PlayerChunkMap#isOutsideRange
++ // Paper start - optimise ChunkMap#anyPlayerCloseEnoughForSpawning
+ this.playerChunkTickRangeMap.update(player, chunkX, chunkZ, DistanceManager.MOB_SPAWN_RANGE);
+ this.playerChunkTickRangeMap.add(player, chunkX, chunkZ, DistanceManager.MOB_SPAWN_RANGE);
-+ // Paper end - optimise PlayerChunkMap#isOutsideRange
++ // Paper end - optimise ChunkMap#anyPlayerCloseEnoughForSpawning
}
void removePlayerFromDistanceMaps(ServerPlayer player) {
-
-+ // Paper start - optimise PlayerChunkMap#isOutsideRange
++ // Paper start - optimise ChunkMap#anyPlayerCloseEnoughForSpawning
+ this.playerMobSpawnMap.remove(player);
+ this.playerChunkTickRangeMap.remove(player);
-+ // Paper end - optimise PlayerChunkMap#isOutsideRange
++ // Paper end - optimise ChunkMap#anyPlayerCloseEnoughForSpawning
}
void updateMaps(ServerPlayer player) {
int chunkX = MCUtil.getChunkCoordinate(player.getX());
int chunkZ = MCUtil.getChunkCoordinate(player.getZ());
// Note: players need to be explicitly added to distance maps before they can be updated
-+ this.playerChunkTickRangeMap.update(player, chunkX, chunkZ, DistanceManager.MOB_SPAWN_RANGE); // Paper - optimise PlayerChunkMap#isOutsideRange
++ this.playerChunkTickRangeMap.update(player, chunkX, chunkZ, DistanceManager.MOB_SPAWN_RANGE); // Paper - optimise ChunkMap#anyPlayerCloseEnoughForSpawning
}
// Paper end
// Paper start
@@ -86,7 +86,7 @@ index f4fddfcb33ae463c6a86e7282d069279258bc4ff..e64d1493c5e77daad2e410647412a2e1
this.regionManagers.add(this.dataRegionManager);
// Paper end
this.playerMobDistanceMap = this.level.paperConfig.perPlayerMobSpawns ? new com.destroystokyo.paper.util.PlayerMobDistanceMap() : null; // Paper
-+ // Paper start - optimise PlayerChunkMap#isOutsideRange
++ // Paper start - optimise ChunkMap#anyPlayerCloseEnoughForSpawning
+ this.playerChunkTickRangeMap = new com.destroystokyo.paper.util.misc.PlayerAreaMap(this.pooledLinkedPlayerHashSets,
+ (ServerPlayer player, int rangeX, int rangeZ, int currPosX, int currPosZ, int prevPosX, int prevPosZ,
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> newState) -> {
@@ -117,7 +117,7 @@ index f4fddfcb33ae463c6a86e7282d069279258bc4ff..e64d1493c5e77daad2e410647412a2e1
+ playerChunk.playersInMobSpawnRange = newState;
+ }
+ });
-+ // Paper end - optimise PlayerChunkMap#isOutsideRange
++ // Paper end - optimise ChunkMap#anyPlayerCloseEnoughForSpawning
}
protected ChunkGenerator generator() {
@@ -125,7 +125,7 @@ index f4fddfcb33ae463c6a86e7282d069279258bc4ff..e64d1493c5e77daad2e410647412a2e1
} else {
if (holder != null) {
holder.setTicketLevel(level);
-+ holder.updateRanges(); // Paper - optimise isOutsideOfRange
++ holder.updateRanges(); // Paper - optimise anyPlayerCloseEnoughForSpawning
}
if (holder != null) {
@@ -143,7 +143,7 @@ index f4fddfcb33ae463c6a86e7282d069279258bc4ff..e64d1493c5e77daad2e410647412a2e1
- double blockRange = 16384.0D; // Paper
- // Spigot end
- long i = chunkcoordintpair.toLong();
-+ // Paper start - optimise isOutsideOfRange
++ // Paper start - optimise anyPlayerCloseEnoughForSpawning
+ final boolean anyPlayerCloseEnoughForSpawning(ChunkPos chunkcoordintpair, boolean reducedRange) {
+ return this.anyPlayerCloseEnoughForSpawning(this.getUpdatingChunkIfPresent(chunkcoordintpair.toLong()), chunkcoordintpair, reducedRange);
+ }
@@ -205,7 +205,7 @@ index f4fddfcb33ae463c6a86e7282d069279258bc4ff..e64d1493c5e77daad2e410647412a2e1
}
+ // no players in range
+ return false;
-+ // Paper end - optimise isOutsideOfRange
++ // Paper end - optimise anyPlayerCloseEnoughForSpawning
}
public List<ServerPlayer> getPlayersCloseForSpawning(ChunkPos pos) {
@@ -272,7 +272,7 @@ index 8868ffcda194e8c2300181a2cdda9337dbde6284..95f195980e28bb59f43e5ca1d5e79ebe
public String getDebugStatus() {
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
-index a66d9d6df1fc0ad68f51ea96d4e1a2d725c73b05..f02643d12ac1959d92e895174b22775ee18a32d8 100644
+index 3c36dfa4f4c6025b02ec455d997f13226de75a64..76b56ea346d843aba482c52c4bfe877fdf0e9225 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -881,6 +881,37 @@ public class ServerChunkCache extends ChunkSource {
@@ -306,7 +306,7 @@ index a66d9d6df1fc0ad68f51ea96d4e1a2d725c73b05..f02643d12ac1959d92e895174b22775e
+ int chunkZ = net.minecraft.server.MCUtil.getChunkCoordinate(player.getZ());
+
+ playerChunkMap.playerMobSpawnMap.addOrUpdate(player, chunkX, chunkZ, range);
-+ player.lastEntitySpawnRadiusSquared = (double)((range << 4) * (range << 4)); // used in isOutsideRange
++ player.lastEntitySpawnRadiusSquared = (double)((range << 4) * (range << 4)); // used in anyPlayerCloseEnoughForSpawning
+ player.playerNaturallySpawnedEvent = event;
+ }
+ // Paper end - optimize isOutisdeRange
@@ -335,10 +335,10 @@ index a66d9d6df1fc0ad68f51ea96d4e1a2d725c73b05..f02643d12ac1959d92e895174b22775e
ChunkPos chunkcoordintpair = chunk1.getPos();
- if (this.level.isPositionEntityTicking(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair)) {
-+ if (this.level.isPositionEntityTicking(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkproviderserver_a.holder, chunkcoordintpair, false)) { // Paper - optimise isOutsideOfRange
++ if (this.level.isPositionEntityTicking(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkproviderserver_a.holder, chunkcoordintpair, false)) { // Paper - optimise anyPlayerCloseEnoughForSpawning
chunk1.incrementInhabitedTime(j);
-- if (flag2 && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && !this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair, true)) { // Spigot
-+ if (flag2 && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkproviderserver_a.holder, chunkcoordintpair, true)) { // Spigot // Paper - optimise isOutsideOfRange
+- if (flag2 && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair, true)) { // Spigot
++ if (flag2 && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkproviderserver_a.holder, chunkcoordintpair, true)) { // Spigot // Paper - optimise anyPlayerCloseEnoughForSpawning
NaturalSpawner.spawnForChunk(this.level, chunk1, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
}