2020-05-23 23:15:40 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 23 May 2020 17:03:41 -0400
|
|
|
|
Subject: [PATCH] Optimize sending packets to nearby locations (sounds/effects)
|
|
|
|
|
|
|
|
Instead of using the entire world or player list, use the distance
|
|
|
|
maps to only iterate players who are even seeing the chunk the packet
|
|
|
|
is originating from.
|
|
|
|
|
|
|
|
This will drastically cut down on packet sending cost for worlds with
|
|
|
|
lots of players in them.
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2020-05-23 23:15:40 +02:00
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
2021-03-16 08:19:45 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2020-05-23 23:15:40 +02:00
|
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
2020-06-26 03:58:00 +02:00
|
|
|
}
|
2020-05-23 23:15:40 +02:00
|
|
|
|
2020-06-26 03:58:00 +02:00
|
|
|
public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, ResourceKey<World> resourcekey, Packet<?> packet) {
|
|
|
|
- for (int i = 0; i < this.players.size(); ++i) {
|
|
|
|
- EntityPlayer entityplayer = (EntityPlayer) this.players.get(i);
|
|
|
|
+ WorldServer world = null;
|
|
|
|
+ if (entityhuman != null && entityhuman.world instanceof WorldServer) {
|
|
|
|
+ world = (WorldServer) entityhuman.world;
|
2020-05-23 23:15:40 +02:00
|
|
|
+ }
|
2020-06-26 03:58:00 +02:00
|
|
|
|
|
|
|
- // CraftBukkit start - Test if player receiving packet can see the source of the packet
|
|
|
|
- if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
|
|
|
|
- continue;
|
|
|
|
+ // Paper start
|
2020-05-23 23:15:40 +02:00
|
|
|
+ if (world == null) {
|
2020-06-26 03:58:00 +02:00
|
|
|
+ world = server.getWorldServer(resourcekey);
|
2020-05-23 23:15:40 +02:00
|
|
|
+ }
|
2020-06-26 03:58:00 +02:00
|
|
|
+ PlayerChunkMap chunkMap = world != null ? world.getChunkProvider().playerChunkMap : null;
|
2020-05-27 06:47:20 +02:00
|
|
|
+ Object[] backingSet;
|
|
|
|
+ if (chunkMap == null) {
|
|
|
|
+ // Really shouldn't happen...
|
2020-06-26 03:58:00 +02:00
|
|
|
+ backingSet = world != null ? world.players.toArray() : players.toArray();
|
2020-05-27 06:47:20 +02:00
|
|
|
+ } else {
|
|
|
|
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<EntityPlayer> nearbyPlayers = chunkMap.playerViewDistanceBroadcastMap.getObjectsInRange(MCUtil.fastFloor(d0) >> 4, MCUtil.fastFloor(d2) >> 4);
|
|
|
|
+ if (nearbyPlayers == null) {
|
|
|
|
+ return;
|
2020-06-26 03:58:00 +02:00
|
|
|
}
|
2020-05-27 06:47:20 +02:00
|
|
|
+ backingSet = nearbyPlayers.getBackingSet();
|
2020-05-24 04:27:37 +02:00
|
|
|
+ }
|
2020-05-27 06:47:20 +02:00
|
|
|
+
|
2020-05-23 23:15:40 +02:00
|
|
|
+ for (Object object : backingSet) {
|
|
|
|
+ if (!(object instanceof EntityPlayer)) continue;
|
|
|
|
+ EntityPlayer entityplayer = (EntityPlayer) object;
|
2020-06-26 03:58:00 +02:00
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
+ // CraftBukkit start - Test if player receiving packet can see the source of the packet
|
|
|
|
+ //if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) { // Paper
|
|
|
|
+ //continue; // Paper
|
|
|
|
+ //} // Paper
|
|
|
|
// CraftBukkit end
|
2020-05-23 23:15:40 +02:00
|
|
|
|
2020-06-26 03:58:00 +02:00
|
|
|
- if (entityplayer != entityhuman && entityplayer.world.getDimensionKey() == resourcekey) {
|
2020-06-26 21:34:52 +02:00
|
|
|
+ if (entityplayer != entityhuman && entityplayer.world.getDimensionKey() == resourcekey && (!(entityhuman instanceof EntityPlayer) || entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity()))) { // Paper
|
2020-06-26 03:58:00 +02:00
|
|
|
double d4 = d0 - entityplayer.locX();
|
|
|
|
double d5 = d1 - entityplayer.locY();
|
|
|
|
double d6 = d2 - entityplayer.locZ();
|