Improved global entity motion encoding using per-player queues

This commit is contained in:
Shoghi Cervantes 2014-11-27 14:26:36 +01:00
parent cd135b39ad
commit 38089af098
10 changed files with 44 additions and 67 deletions

View File

@ -93,8 +93,10 @@ use pocketmine\network\protocol\FullChunkDataPacket;
use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\Info as ProtocolInfo;
use pocketmine\network\protocol\LoginStatusPacket; use pocketmine\network\protocol\LoginStatusPacket;
use pocketmine\network\protocol\MessagePacket; use pocketmine\network\protocol\MessagePacket;
use pocketmine\network\protocol\MoveEntityPacket;
use pocketmine\network\protocol\MovePlayerPacket; use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\network\protocol\SetDifficultyPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\network\protocol\SetHealthPacket; use pocketmine\network\protocol\SetHealthPacket;
use pocketmine\network\protocol\SetSpawnPositionPacket; use pocketmine\network\protocol\SetSpawnPositionPacket;
use pocketmine\network\protocol\SetTimePacket; use pocketmine\network\protocol\SetTimePacket;
@ -142,6 +144,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
protected $sendIndex = 0; protected $sendIndex = 0;
protected $moveToSend = [];
protected $motionToSend = [];
public $blocked = false; public $blocked = false;
public $achievements = []; public $achievements = [];
public $lastCorrect; public $lastCorrect;
@ -1053,6 +1058,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return -1; return -1;
} }
public function addEntityMotion($entityId, $x, $y, $z){
$this->motionToSend[$entityId] = [$entityId, $x, $y, $z];
}
public function addEntityMovement($entityId, $x, $y, $z, $yaw, $pitch){
$this->moveToSend[$entityId] = [$entityId, $x, $y, $z, $yaw, $pitch];
}
protected function processMovement($currentTick){ protected function processMovement($currentTick){
if($this->dead or !$this->spawned or !($this->newPosition instanceof Vector3)){ if($this->dead or !$this->spawned or !($this->newPosition instanceof Vector3)){
return; return;
@ -1271,6 +1284,21 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->sendNextChunk(); $this->sendNextChunk();
} }
if(count($this->moveToSend) > 0){
$pk = new MoveEntityPacket();
$pk->entities = $this->moveToSend;
$this->dataPacket($pk);
$this->moveToSend = [];
}
if(count($this->motionToSend) > 0){
$pk = new SetEntityMotionPacket();
$pk->entities = $this->motionToSend;
$this->dataPacket($pk);
$this->motionToSend = [];
}
$this->timings->stopTiming(); $this->timings->stopTiming();
return true; return true;

View File

@ -24,7 +24,6 @@ namespace pocketmine\entity;
use pocketmine\level\format\FullChunk; use pocketmine\level\format\FullChunk;
use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Compound;
use pocketmine\network\protocol\AddEntityPacket; use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Player; use pocketmine\Player;
class Arrow extends Projectile{ class Arrow extends Projectile{
@ -73,11 +72,7 @@ class Arrow extends Projectile{
$pk->did = 0; //TODO: send motion here $pk->did = 0; //TODO: send motion here
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket(); $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
parent::spawnTo($player); parent::spawnTo($player);
} }

View File

@ -51,11 +51,9 @@ use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\Short; use pocketmine\nbt\tag\Short;
use pocketmine\nbt\tag\String; use pocketmine\nbt\tag\String;
use pocketmine\Network; use pocketmine\Network;
use pocketmine\network\protocol\MoveEntityPacket;
use pocketmine\network\protocol\MovePlayerPacket; use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\RemoveEntityPacket; use pocketmine\network\protocol\RemoveEntityPacket;
use pocketmine\network\protocol\SetEntityDataPacket; use pocketmine\network\protocol\SetEntityDataPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\network\protocol\SetTimePacket; use pocketmine\network\protocol\SetTimePacket;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
@ -594,15 +592,13 @@ abstract class Entity extends Location implements Metadatable{
$pk->yaw = $this->yaw; $pk->yaw = $this->yaw;
$pk->pitch = $this->pitch; $pk->pitch = $this->pitch;
$pk->bodyYaw = $this->yaw; $pk->bodyYaw = $this->yaw;
Server::broadcastPacket($this->hasSpawned, $pk);
}else{ }else{
//TODO: add to move list foreach($this->hasSpawned as $player){
$pk = new MoveEntityPacket(); $player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch);
$pk->entities = [ }
[$this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch]
];
} }
Server::broadcastPacket($this->hasSpawned, $pk);
} }
if(($this->lastMotionX != $this->motionX or $this->lastMotionY != $this->motionY or $this->lastMotionZ != $this->motionZ)){ if(($this->lastMotionX != $this->motionX or $this->lastMotionY != $this->motionY or $this->lastMotionZ != $this->motionZ)){
@ -610,12 +606,9 @@ abstract class Entity extends Location implements Metadatable{
$this->lastMotionY = $this->motionY; $this->lastMotionY = $this->motionY;
$this->lastMotionZ = $this->motionZ; $this->lastMotionZ = $this->motionZ;
$pk = new SetEntityMotionPacket(); foreach($this->hasSpawned as $player){
$pk->entities = [ $player->addEntityMotion($this->id, $this->motionX, $this->motionY, $this->motionZ);
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] }
];
Server::broadcastPacket($this->hasSpawned, $pk);
if($this instanceof Player){ if($this instanceof Player){
$this->motionX = 0; $this->motionX = 0;
@ -1152,11 +1145,7 @@ abstract class Entity extends Location implements Metadatable{
if(!$this->justCreated){ if(!$this->justCreated){
if($this instanceof Player){ if($this instanceof Player){
$pk = new SetEntityMotionPacket(); $this->addEntityMotion(0, $this->motionX, $this->motionY, $this->motionZ);
$pk->entities = [
[0, $this->motionX, $this->motionY, $this->motionZ]
];
$this->dataPacket($pk);
} }
$this->updateMovement(); $this->updateMovement();
} }

View File

@ -31,7 +31,6 @@ use pocketmine\math\Vector3;
use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\Int;
use pocketmine\network\protocol\AddEntityPacket; use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Player; use pocketmine\Player;
class FallingSand extends Entity{ class FallingSand extends Entity{
@ -159,11 +158,7 @@ class FallingSand extends Entity{
$pk->did = -($this->getBlock() | $this->getDamage() << 0x10); $pk->did = -($this->getBlock() | $this->getDamage() << 0x10);
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket(); $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
parent::spawnTo($player); parent::spawnTo($player);
} }

View File

@ -32,7 +32,6 @@ use pocketmine\nbt\tag\Short;
use pocketmine\Network; use pocketmine\Network;
use pocketmine\network\protocol\AddPlayerPacket; use pocketmine\network\protocol\AddPlayerPacket;
use pocketmine\network\protocol\RemovePlayerPacket; use pocketmine\network\protocol\RemovePlayerPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -175,11 +174,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$pk->metadata = $this->getData(); $pk->metadata = $this->getData();
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket(); $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
$this->inventory->sendArmorContents($player); $this->inventory->sendArmorContents($player);
} }

View File

@ -32,7 +32,6 @@ use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Short; use pocketmine\nbt\tag\Short;
use pocketmine\nbt\tag\String; use pocketmine\nbt\tag\String;
use pocketmine\network\protocol\AddItemEntityPacket; use pocketmine\network\protocol\AddItemEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Player; use pocketmine\Player;
class Item extends Entity{ class Item extends Entity{
@ -237,11 +236,7 @@ class Item extends Entity{
$pk->item = $this->getItem(); $pk->item = $this->getItem();
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket(); $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
parent::spawnTo($player); parent::spawnTo($player);
} }

View File

@ -28,7 +28,6 @@ use pocketmine\event\entity\ExplosionPrimeEvent;
use pocketmine\level\Explosion; use pocketmine\level\Explosion;
use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Byte;
use pocketmine\network\protocol\AddEntityPacket; use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Player; use pocketmine\Player;
class PrimedTNT extends Entity implements Explosive{ class PrimedTNT extends Entity implements Explosive{
@ -147,11 +146,7 @@ class PrimedTNT extends Entity implements Explosive{
$pk->did = 0; $pk->did = 0;
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket(); $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
parent::spawnTo($player); parent::spawnTo($player);
} }

View File

@ -25,7 +25,6 @@ namespace pocketmine\entity;
use pocketmine\level\format\FullChunk; use pocketmine\level\format\FullChunk;
use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Compound;
use pocketmine\network\protocol\AddEntityPacket; use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Player; use pocketmine\Player;
class Snowball extends Projectile{ class Snowball extends Projectile{
@ -72,11 +71,7 @@ class Snowball extends Projectile{
$pk->did = 0; //TODO: send motion here $pk->did = 0; //TODO: send motion here
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket(); $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
parent::spawnTo($player); parent::spawnTo($player);
} }

View File

@ -24,7 +24,6 @@ namespace pocketmine\entity;
use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\Int;
use pocketmine\network\protocol\AddMobPacket; use pocketmine\network\protocol\AddMobPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Player; use pocketmine\Player;
class Villager extends Creature implements NPC, Ageable{ class Villager extends Creature implements NPC, Ageable{
@ -64,11 +63,7 @@ class Villager extends Creature implements NPC, Ageable{
$pk->metadata = $this->getData(); $pk->metadata = $this->getData();
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket(); $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
parent::spawnTo($player); parent::spawnTo($player);
} }

View File

@ -25,7 +25,6 @@ namespace pocketmine\entity;
use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item as ItemItem;
use pocketmine\network\protocol\AddMobPacket; use pocketmine\network\protocol\AddMobPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Player; use pocketmine\Player;
class Zombie extends Monster{ class Zombie extends Monster{
@ -52,11 +51,7 @@ class Zombie extends Monster{
$pk->metadata = $this->getData(); $pk->metadata = $this->getData();
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket(); $player->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
parent::spawnTo($player); parent::spawnTo($player);
} }