From c26631d06dd40fb6204c6135dba8117ffc0f1fc5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 24 Jul 2022 20:44:27 +0100 Subject: [PATCH] InGamePacketHandler: avoid useless object allocations when forceMoveSync=false (99.9% of the time) --- .../mcpe/handler/InGamePacketHandler.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index c4e151d4f..0306be57c 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -197,17 +197,20 @@ class InGamePacketHandler extends PacketHandler{ $this->player->setRotation($yaw, $pitch); - $curPos = $this->player->getLocation(); $newPos = $rawPos->round(4)->subtract(0, 1.62, 0); - if($this->forceMoveSync && $newPos->distanceSquared($curPos) > 1){ //Tolerate up to 1 block to avoid problems with client-sided physics when spawning in blocks - $this->session->getLogger()->debug("Got outdated pre-teleport movement, received " . $newPos . ", expected " . $curPos); - //Still getting movements from before teleport, ignore them - return false; - } + if($this->forceMoveSync){ + $curPos = $this->player->getLocation(); - // Once we get a movement within a reasonable distance, treat it as a teleport ACK and remove position lock - $this->forceMoveSync = false; + if($newPos->distanceSquared($curPos) > 1){ //Tolerate up to 1 block to avoid problems with client-sided physics when spawning in blocks + $this->session->getLogger()->debug("Got outdated pre-teleport movement, received " . $newPos . ", expected " . $curPos); + //Still getting movements from before teleport, ignore them + return false; + } + + // Once we get a movement within a reasonable distance, treat it as a teleport ACK and remove position lock + $this->forceMoveSync = false; + } $inputFlags = $packet->getInputFlags(); if($inputFlags !== $this->lastPlayerAuthInputFlags){