mirror of
https://github.com/PaperMC/Paper.git
synced 2025-09-02 21:33:52 -07:00
Remove duplicate code in chunk tick iteration (#10056)
This commit is contained in:
@@ -196,48 +196,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
gameprofilerfiller.push("filteringLoadedChunks");
|
gameprofilerfiller.push("filteringLoadedChunks");
|
||||||
- List<ServerChunkCache.ChunkAndHolder> list = Lists.newArrayListWithCapacity(this.chunkMap.size());
|
- List<ServerChunkCache.ChunkAndHolder> list = Lists.newArrayListWithCapacity(this.chunkMap.size());
|
||||||
- Iterator iterator = this.chunkMap.getChunks().iterator();
|
- Iterator iterator = this.chunkMap.getChunks().iterator();
|
||||||
|
+ // Paper - optimise chunk tick iteration
|
||||||
if (this.level.getServer().tickRateManager().runsNormally()) this.level.timings.chunkTicks.startTiming(); // Paper
|
if (this.level.getServer().tickRateManager().runsNormally()) this.level.timings.chunkTicks.startTiming(); // Paper
|
||||||
|
|
||||||
- while (iterator.hasNext()) {
|
- while (iterator.hasNext()) {
|
||||||
- ChunkHolder playerchunk = (ChunkHolder) iterator.next();
|
- ChunkHolder playerchunk = (ChunkHolder) iterator.next();
|
||||||
- LevelChunk chunk = playerchunk.getTickingChunk();
|
- LevelChunk chunk = playerchunk.getTickingChunk();
|
||||||
+ // Paper start - optimise chunk tick iteration
|
-
|
||||||
+ ChunkMap playerChunkMap = this.chunkMap;
|
|
||||||
+ for (ServerPlayer player : this.level.players) {
|
|
||||||
+ if (!player.affectsSpawning || player.isSpectator()) {
|
|
||||||
+ playerChunkMap.playerMobSpawnMap.remove(player);
|
|
||||||
+ player.playerNaturallySpawnedEvent = null;
|
|
||||||
+ player.lastEntitySpawnRadiusSquared = -1.0;
|
|
||||||
+ continue;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ int viewDistance = io.papermc.paper.chunk.system.ChunkSystem.getTickViewDistance(player);
|
|
||||||
|
|
||||||
- if (chunk != null) {
|
- if (chunk != null) {
|
||||||
- list.add(new ServerChunkCache.ChunkAndHolder(chunk, playerchunk));
|
- list.add(new ServerChunkCache.ChunkAndHolder(chunk, playerchunk));
|
||||||
+ // copied and modified from isOutisdeRange
|
- }
|
||||||
+ int chunkRange = (int)level.spigotConfig.mobSpawnRange;
|
- }
|
||||||
+ chunkRange = (chunkRange > viewDistance) ? viewDistance : chunkRange;
|
+ // Paper - optimise chunk tick iteration
|
||||||
+ chunkRange = (chunkRange > DistanceManager.MOB_SPAWN_RANGE) ? DistanceManager.MOB_SPAWN_RANGE : chunkRange;
|
|
||||||
+
|
|
||||||
+ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(player.getBukkitEntity(), (byte)chunkRange);
|
|
||||||
+ event.callEvent();
|
|
||||||
+ if (event.isCancelled() || event.getSpawnRadius() < 0) {
|
|
||||||
+ playerChunkMap.playerMobSpawnMap.remove(player);
|
|
||||||
+ player.playerNaturallySpawnedEvent = null;
|
|
||||||
+ player.lastEntitySpawnRadiusSquared = -1.0;
|
|
||||||
+ continue;
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+ int range = Math.min(event.getSpawnRadius(), DistanceManager.MOB_SPAWN_RANGE); // limit to max spawn range
|
|
||||||
+ int chunkX = io.papermc.paper.util.CoordinateUtils.getChunkCoordinate(player.getX());
|
|
||||||
+ int chunkZ = io.papermc.paper.util.CoordinateUtils.getChunkCoordinate(player.getZ());
|
|
||||||
+
|
|
||||||
+ playerChunkMap.playerMobSpawnMap.addOrUpdate(player, chunkX, chunkZ, range);
|
|
||||||
+ player.lastEntitySpawnRadiusSquared = (double)((range << 4) * (range << 4)); // used in anyPlayerCloseEnoughForSpawning
|
|
||||||
+ player.playerNaturallySpawnedEvent = event;
|
|
||||||
}
|
|
||||||
+ // Paper end - optimise chunk tick iteration
|
|
||||||
|
|
||||||
if (this.level.getServer().tickRateManager().runsNormally()) {
|
if (this.level.getServer().tickRateManager().runsNormally()) {
|
||||||
gameprofilerfiller.popPush("naturalSpawnCount");
|
gameprofilerfiller.popPush("naturalSpawnCount");
|
||||||
@@ -254,6 +224,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
- entityPlayer.playerNaturallySpawnedEvent = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityPlayer.getBukkitEntity(), (byte) chunkRange);
|
- entityPlayer.playerNaturallySpawnedEvent = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityPlayer.getBukkitEntity(), (byte) chunkRange);
|
||||||
- entityPlayer.playerNaturallySpawnedEvent.callEvent();
|
- entityPlayer.playerNaturallySpawnedEvent.callEvent();
|
||||||
+ // Paper start - optimise chunk tick iteration
|
+ // Paper start - optimise chunk tick iteration
|
||||||
|
+ ChunkMap playerChunkMap = this.chunkMap;
|
||||||
+ for (ServerPlayer player : this.level.players) {
|
+ for (ServerPlayer player : this.level.players) {
|
||||||
+ if (!player.affectsSpawning || player.isSpectator()) {
|
+ if (!player.affectsSpawning || player.isSpectator()) {
|
||||||
+ playerChunkMap.playerMobSpawnMap.remove(player);
|
+ playerChunkMap.playerMobSpawnMap.remove(player);
|
||||||
@@ -291,6 +262,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
int l = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
|
int l = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
|
||||||
boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
|
boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
|
||||||
- Iterator iterator1 = list.iterator();
|
- Iterator iterator1 = list.iterator();
|
||||||
|
+ // Paper - optimise chunk tick iteration
|
||||||
|
|
||||||
int chunksTicked = 0; // Paper
|
int chunksTicked = 0; // Paper
|
||||||
- while (iterator1.hasNext()) {
|
- while (iterator1.hasNext()) {
|
||||||
@@ -313,7 +285,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ try {
|
+ try {
|
||||||
+ // Paper end - optimise chunk tick iteration
|
+ // Paper end - optimise chunk tick iteration
|
||||||
+ while (chunkIterator.hasNext()) {
|
+ while (chunkIterator.hasNext()) {
|
||||||
+ LevelChunk chunk1 = chunkIterator.next(); // Paper - optimise chunk tick iteration
|
+ LevelChunk chunk1 = chunkIterator.next();
|
||||||
|
+ // Paper end - optimise chunk tick iteration
|
||||||
ChunkPos chunkcoordintpair = chunk1.getPos();
|
ChunkPos chunkcoordintpair = chunk1.getPos();
|
||||||
|
|
||||||
- if (this.level.isNaturalSpawningAllowed(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair)) {
|
- if (this.level.isNaturalSpawningAllowed(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair)) {
|
||||||
@@ -323,7 +296,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ if (playersNearby == null) {
|
+ if (playersNearby == null) {
|
||||||
+ continue;
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
+
|
|
||||||
+ Object[] rawData = playersNearby.getRawData();
|
+ Object[] rawData = playersNearby.getRawData();
|
||||||
+ boolean spawn = false;
|
+ boolean spawn = false;
|
||||||
+ boolean tick = false;
|
+ boolean tick = false;
|
||||||
|
Reference in New Issue
Block a user