From 044b25ccd2c7a149c19334a6f87c9e43c8f08ee0 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 26 May 2013 19:58:23 +0200 Subject: [PATCH] Faster chunk distance ordering --- src/Player.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Player.php b/src/Player.php index 6a9dd4204..48f914b87 100644 --- a/src/Player.php +++ b/src/Player.php @@ -123,14 +123,17 @@ class Player{ $X = $this->entity->x / 16; $Z = $this->entity->z / 16; $Y = $this->entity->y / 16; - $v = new Vector3($X, $Y / 4, $Z); + $this->chunksOrder = array(); - for($x = 0; $x < 16; ++$x){ - for($z = 0; $z < 16; ++$z){ - for($y = 0; $y < 8; ++$y){ + for($y = 0; $y < 8; ++$y){ + $distY = abs($Y - $y) / 4; + for($x = 0; $x < 16; ++$x){ + $distX = abs($X - $x); + for($z = 0; $z < 16; ++$z){ + $distZ = abs($Z - $z); $d = $x.":".$y.":".$z; if(!isset($this->chunksLoaded[$d])){ - $this->chunksOrder[$d] = $v->distance(new Vector3($x + 0.5, $y / 4, $z + 0.5)); + $this->chunksOrder[$d] = $distX + $distY + $distZ; } } }