mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 08:49:42 +00:00
World: do not group broadcasted packets by chunk, broadcast directly instead
Grouping packets to batch by chunk instead of by player reduces bandwidth efficiency, because the number of active chunks is almost always larger than the number of active players. With the old mechanism, a batch of packets for each active chunk (which could be dozens, or hundreds... or thousands) would be created once, and then sent to many players. This makes the compression load factor O(nActiveChunks). Broadcasting directly is simpler and changes the load factor to O(nActivePlayers), which usually means a smaller number of larger batches are created, achieving better compression ratios for approximately the same cost (the same amount of data is being compressed, just in a different way).
This commit is contained in:
parent
78bddac823
commit
b172c93e45
@ -172,9 +172,6 @@ class World implements ChunkManager{
|
||||
/** @var Player[][] */
|
||||
private $playerChunkListeners = [];
|
||||
|
||||
/** @var ClientboundPacket[][] */
|
||||
private $chunkPackets = [];
|
||||
|
||||
/** @var float[] */
|
||||
private $unloadQueue = [];
|
||||
|
||||
@ -525,11 +522,7 @@ class World implements ChunkManager{
|
||||
* Broadcasts a packet to every player who has the target position within their view distance.
|
||||
*/
|
||||
public function broadcastPacketToViewers(Vector3 $pos, ClientboundPacket $packet) : void{
|
||||
if(!isset($this->chunkPackets[$index = World::chunkHash($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4)])){
|
||||
$this->chunkPackets[$index] = [$packet];
|
||||
}else{
|
||||
$this->chunkPackets[$index][] = $packet;
|
||||
}
|
||||
$this->server->broadcastPackets($this->getChunkPlayers($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4), [$packet]);
|
||||
}
|
||||
|
||||
public function registerChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ, bool $autoLoad = true) : void{
|
||||
@ -775,16 +768,6 @@ class World implements ChunkManager{
|
||||
if($this->sleepTicks > 0 and --$this->sleepTicks <= 0){
|
||||
$this->checkSleep();
|
||||
}
|
||||
|
||||
foreach($this->chunkPackets as $index => $entries){
|
||||
World::getXZ($index, $chunkX, $chunkZ);
|
||||
$chunkPlayers = $this->getChunkPlayers($chunkX, $chunkZ);
|
||||
if(count($chunkPlayers) > 0){
|
||||
$this->server->broadcastPackets($chunkPlayers, $entries);
|
||||
}
|
||||
}
|
||||
|
||||
$this->chunkPackets = [];
|
||||
}
|
||||
|
||||
public function checkSleep() : void{
|
||||
|
Loading…
x
Reference in New Issue
Block a user