Entity: get rid of temporalVector mutation

except for checkBlockCollision, these are all cold paths ... this gets us one step closer to immutable Vector3
This commit is contained in:
Dylan K. Taylor 2020-06-20 21:41:19 +01:00
parent 42637f97c6
commit 80e150c803

View File

@ -115,9 +115,6 @@ abstract class Entity{
/** @var bool */ /** @var bool */
protected $forceMovementUpdate = false; protected $forceMovementUpdate = false;
/** @var Vector3 */
public $temporalVector;
/** @var AxisAlignedBB */ /** @var AxisAlignedBB */
public $boundingBox; public $boundingBox;
/** @var bool */ /** @var bool */
@ -224,8 +221,6 @@ abstract class Entity{
public function __construct(Location $location, ?CompoundTag $nbt = null){ public function __construct(Location $location, ?CompoundTag $nbt = null){
$this->timings = Timings::getEntityTimings($this); $this->timings = Timings::getEntityTimings($this);
$this->temporalVector = new Vector3(0, 0, 0);
if($this->eyeHeight === null){ if($this->eyeHeight === null){
$this->eyeHeight = $this->height / 2 + 0.1; $this->eyeHeight = $this->height / 2 + 0.1;
} }
@ -918,7 +913,7 @@ abstract class Entity{
$x = -$xz * sin(deg2rad($this->location->yaw)); $x = -$xz * sin(deg2rad($this->location->yaw));
$z = $xz * cos(deg2rad($this->location->yaw)); $z = $xz * cos(deg2rad($this->location->yaw));
return $this->temporalVector->setComponents($x, $y, $z)->normalize(); return (new Vector3($x, $y, $z))->normalize();
} }
public function getDirectionPlane() : Vector2{ public function getDirectionPlane() : Vector2{
@ -1267,7 +1262,7 @@ abstract class Entity{
} }
protected function checkBlockCollision() : void{ protected function checkBlockCollision() : void{
$vector = $this->temporalVector->setComponents(0, 0, 0); $vector = new Vector3(0, 0, 0);
foreach($this->getBlocksAround() as $block){ foreach($this->getBlocksAround() as $block){
$block->onEntityInside($this); $block->onEntityInside($this);
@ -1423,7 +1418,7 @@ abstract class Entity{
} }
$pos = $ev->getTo(); $pos = $ev->getTo();
$this->setMotion($this->temporalVector->setComponents(0, 0, 0)); $this->setMotion(new Vector3(0, 0, 0));
if($this->setPositionAndRotation($pos, $yaw ?? $this->location->yaw, $pitch ?? $this->location->pitch)){ if($this->setPositionAndRotation($pos, $yaw ?? $this->location->yaw, $pitch ?? $this->location->pitch)){
$this->resetFallDistance(); $this->resetFallDistance();
$this->setForceMovementUpdate(); $this->setForceMovementUpdate();