Improved network packets allocation

This commit is contained in:
Shoghi Cervantes
2014-10-27 20:30:33 +01:00
parent 3f5b129cf5
commit db82f76c11
69 changed files with 366 additions and 222 deletions

View File

@@ -209,7 +209,7 @@ class Arrow extends Projectile{
}
public function spawnTo(Player $player){
$pk = new AddEntityPacket();
$pk = AddEntityPacket::getFromPool();
$pk->type = Arrow::NETWORK_ID;
$pk->eid = $this->getID();
$pk->x = $this->x;
@@ -218,7 +218,7 @@ class Arrow extends Projectile{
$pk->did = 0; //TODO: send motion here
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket();
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -219,7 +219,7 @@ class DroppedItem extends Entity{
}
public function spawnTo(Player $player){
$pk = new AddItemEntityPacket();
$pk = AddItemEntityPacket::getFromPool();
$pk->eid = $this->getID();
$pk->x = $this->x;
$pk->y = $this->y;
@@ -230,7 +230,7 @@ class DroppedItem extends Entity{
$pk->item = $this->getItem();
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -270,7 +270,7 @@ abstract class Entity extends Location implements Metadatable{
$player = [$player];
}
$pk = new SetEntityDataPacket();
$pk = SetEntityDataPacket::getFromPool();
$pk->eid = $this->id;
$pk->metadata = $this->getData();
$pk->encode();
@@ -278,7 +278,7 @@ abstract class Entity extends Location implements Metadatable{
foreach($player as $p){
if($p === $this){
/** @var Player $p */
$pk2 = new SetEntityDataPacket();
$pk2 = SetEntityDataPacket::getFromPool();
$pk2->eid = 0;
$pk2->metadata = $this->getData();
$p->dataPacket($pk2);
@@ -293,7 +293,7 @@ abstract class Entity extends Location implements Metadatable{
*/
public function despawnFrom(Player $player){
if(isset($this->hasSpawned[$player->getID()])){
$pk = new RemoveEntityPacket;
$pk = RemoveEntityPacket::getFromPool();
$pk->eid = $this->id;
$player->dataPacket($pk);
unset($this->hasSpawned[$player->getID()]);
@@ -532,7 +532,7 @@ abstract class Entity extends Location implements Metadatable{
$this->lastPitch = $this->pitch;
if($this instanceof Human){
$pk = new MovePlayerPacket;
$pk = MovePlayerPacket::getFromPool();
$pk->eid = $this->id;
$pk->x = $this->x;
$pk->y = $this->y;
@@ -542,7 +542,7 @@ abstract class Entity extends Location implements Metadatable{
$pk->bodyYaw = $this->yaw;
}else{
//TODO: add to move list
$pk = new MoveEntityPacket();
$pk = MoveEntityPacket::getFromPool();
$pk->entities = [
[$this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch]
];
@@ -556,7 +556,7 @@ abstract class Entity extends Location implements Metadatable{
$this->lastMotionY = $this->motionY;
$this->lastMotionZ = $this->motionZ;
$pk = new SetEntityMotionPacket;
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
@@ -726,7 +726,7 @@ abstract class Entity extends Location implements Metadatable{
$this->level->addEntity($this);
if($this instanceof Player){
$this->usedChunks = [];
$pk = new SetTimePacket();
$pk = SetTimePacket::getFromPool();
$pk->time = $this->level->getTime();
$pk->started = $this->level->stopTime == false;
$this->dataPacket($pk);
@@ -1100,7 +1100,7 @@ abstract class Entity extends Location implements Metadatable{
if(!$this->justCreated){
if($this instanceof Player){
$pk = new SetEntityMotionPacket;
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[0, $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -150,7 +150,7 @@ class FallingBlock extends Entity{
}
public function spawnTo(Player $player){
$pk = new AddEntityPacket;
$pk = AddEntityPacket::getFromPool();
$pk->type = FallingBlock::NETWORK_ID;
$pk->eid = $this->getID();
$pk->x = $this->x;
@@ -159,7 +159,7 @@ class FallingBlock extends Entity{
$pk->did = -$this->getBlock();
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -156,7 +156,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($player !== $this and !isset($this->hasSpawned[$player->getID()])){
$this->hasSpawned[$player->getID()] = $player;
$pk = new AddPlayerPacket;
$pk = AddPlayerPacket::getFromPool();
$pk->clientID = 0;
if($player->getRemoveFormat()){
$pk->username = TextFormat::clean($this->nameTag);
@@ -174,7 +174,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$pk->metadata = $this->getData();
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
@@ -188,7 +188,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public function despawnFrom(Player $player){
if(isset($this->hasSpawned[$player->getID()])){
$pk = new RemovePlayerPacket;
$pk = RemovePlayerPacket::getFromPool();
$pk->eid = $this->id;
$pk->clientID = 0;
$player->dataPacket($pk);

View File

@@ -76,7 +76,7 @@ abstract class Living extends Entity implements Damageable{
}
}
$pk = new EntityEventPacket();
$pk = EntityEventPacket::getFromPool();
$pk->eid = $this->getID();
$pk->event = 2; //Ouch!
Server::broadcastPacket($this->hasSpawned, $pk);

View File

@@ -140,7 +140,7 @@ class PrimedTNT extends Entity implements Explosive{
}
public function spawnTo(Player $player){
$pk = new AddEntityPacket();
$pk = AddEntityPacket::getFromPool();
$pk->type = PrimedTNT::NETWORK_ID;
$pk->eid = $this->getID();
$pk->x = $this->x;
@@ -149,7 +149,7 @@ class PrimedTNT extends Entity implements Explosive{
$pk->did = 0;
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket();
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -55,7 +55,7 @@ class Villager extends Creature implements NPC, Ageable{
}
public function spawnTo(Player $player){
$pk = new AddMobPacket();
$pk = AddMobPacket::getFromPool();
$pk->eid = $this->getID();
$pk->type = Villager::NETWORK_ID;
$pk->x = $this->x;
@@ -66,7 +66,7 @@ class Villager extends Creature implements NPC, Ageable{
$pk->metadata = $this->getData();
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket();
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -46,7 +46,7 @@ class Zombie extends Monster{
public function spawnTo(Player $player){
$pk = new AddMobPacket();
$pk = AddMobPacket::getFromPool();
$pk->eid = $this->getID();
$pk->type = Zombie::NETWORK_ID;
$pk->x = $this->x;
@@ -57,7 +57,7 @@ class Zombie extends Monster{
$pk->metadata = $this->getData();
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket();
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];