From 1c03c3afcfa318354b83f1bfd8ecb3ca6f07c5c9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 17 Oct 2014 09:57:18 +0200 Subject: [PATCH] Decreased chunk ordering times --- src/pocketmine/Player.php | 13 ++++++------- src/pocketmine/network/protocol/DataPacket.php | 3 ++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 38d63509b7..8058cb3e49 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -695,8 +695,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ ++$count; $chunkX = $X + $centerX; $chunkZ = $Z + $centerZ; - $index = Level::chunkHash($chunkX, $chunkZ); - if(!isset($this->usedChunks[$index])){ + if(!isset($this->usedChunks[$index = "$chunkX:$chunkZ"])){ $newOrder[$index] = abs($X) + abs($Z); } unset($lastChunk[$index]); @@ -1057,11 +1056,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $oldPos = new Vector3($this->x, $this->y, $this->z); - $distance = $oldPos->distance($this->newPosition); + $distanceSquared = $oldPos->distanceSquared($this->newPosition); $revert = false; - if($distance > 100){ + if($distanceSquared > 10000){ $revert = true; }else{ if($this->chunk === null or !$this->chunk->isGenerated()){ @@ -1072,7 +1071,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } - if(!$revert and $distance != 0){ + if(!$revert and $distanceSquared != 0){ $dx = $this->newPosition->x - $this->x; $dy = $this->newPosition->y - $this->y; $dz = $this->newPosition->z - $this->z; @@ -1153,8 +1152,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->forceMovement = new Vector3($from->x, $from->y, $from->z); }else{ $this->forceMovement = null; - if($this->nextChunkOrderRun > 4){ - $this->nextChunkOrderRun = 4; + if($this->nextChunkOrderRun > 20){ + $this->nextChunkOrderRun = 20; } } } diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index 8ee9b96017..b3ab23f742 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -36,7 +36,8 @@ abstract class DataPacket extends \stdClass{ abstract public function decode(); protected function reset(){ - $this->setBuffer(chr($this->pid())); + $this->buffer = chr($this->pid()); + $this->offset = 0; } public function setBuffer($buffer = ""){