From 0f9d5f70113fded96aa823d2881f1edc9914f987 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 17 Oct 2020 16:09:30 +0100 Subject: [PATCH] ext-morton is now required and used for World::chunkHash() and World::chunkBlockHash() --- build/php | 2 +- build/preprocessor | 2 +- composer.json | 1 + composer.lock | 3 ++- src/PocketMine.php | 1 + src/world/World.php | 12 ++++++++---- tests/travis/setup-php.yml | 9 +++++++++ 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/build/php b/build/php index bc8e1cf00..7da8425e6 160000 --- a/build/php +++ b/build/php @@ -1 +1 @@ -Subproject commit bc8e1cf0015d9c74feaecdb5bf6c3bf9b9e80489 +Subproject commit 7da8425e677c68d8884788f2917fee2804f25c5a diff --git a/build/preprocessor b/build/preprocessor index 0400f8532..c8c0557dd 160000 --- a/build/preprocessor +++ b/build/preprocessor @@ -1 +1 @@ -Subproject commit 0400f85329092be8ffaaca1b6921a18fae7848e1 +Subproject commit c8c0557ddf159413352de2a74a013d40fbfe3a69 diff --git a/composer.json b/composer.json index 112f65676..ea0faa1e8 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "ext-json": "*", "ext-leveldb": "^0.2.1", "ext-mbstring": "*", + "ext-morton": "^0.1.0", "ext-openssl": "*", "ext-pcre": "*", "ext-phar": "*", diff --git a/composer.lock b/composer.lock index a2552124f..50163622f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7fdb5abb5388f1e92229efff1f783d40", + "content-hash": "cfc91763774445e65e366642b2efdde1", "packages": [ { "name": "adhocore/json-comment", @@ -3104,6 +3104,7 @@ "ext-json": "*", "ext-leveldb": "^0.2.1", "ext-mbstring": "*", + "ext-morton": "^0.1.0", "ext-openssl": "*", "ext-pcre": "*", "ext-phar": "*", diff --git a/src/PocketMine.php b/src/PocketMine.php index d5b842d30..3f6212a18 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -88,6 +88,7 @@ namespace pocketmine { "json" => "JSON", "leveldb" => "LevelDB", "mbstring" => "Multibyte String", + "morton" => "morton", "openssl" => "OpenSSL", "pcre" => "PCRE", "phar" => "Phar", diff --git a/src/world/World.php b/src/world/World.php index eeb85d567..757ef04cf 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -96,6 +96,9 @@ use function lcg_value; use function max; use function microtime; use function min; +use function morton2d_decode; +use function morton2d_encode; +use function morton3d_encode; use function mt_rand; use function spl_object_id; use function strtolower; @@ -268,10 +271,11 @@ class World implements ChunkManager{ private $logger; public static function chunkHash(int $x, int $z) : int{ - return (($x & 0xFFFFFFFF) << 32) | ($z & 0xFFFFFFFF); + return morton2d_encode($x, $z); } public static function blockHash(int $x, int $y, int $z) : int{ + //TODO: switch this to use morton3d (21 bits each only allows for 2M blocks, but Y would have 12 spare bits) $shiftedY = $y - self::HALF_Y_MAX; if($shiftedY < -512 or $shiftedY >= 512){ throw new \InvalidArgumentException("Y coordinate $y is out of range!"); @@ -283,18 +287,18 @@ class World implements ChunkManager{ * Computes a small index relative to chunk base from the given coordinates. */ public static function chunkBlockHash(int $x, int $y, int $z) : int{ - return ($y << 8) | (($z & 0xf) << 4) | ($x & 0xf); + return morton3d_encode($x, $y, $z); } public static function getBlockXYZ(int $hash, ?int &$x, ?int &$y, ?int &$z) : void{ + //TODO: switch this to use morton3d $x = $hash >> 37; $y = ($hash << 27 >> 54) + self::HALF_Y_MAX; $z = $hash << 37 >> 37; } public static function getXZ(int $hash, ?int &$x, ?int &$z) : void{ - $x = $hash >> 32; - $z = ($hash & 0xFFFFFFFF) << 32 >> 32; + [$x, $z] = morton2d_decode($hash); } public static function getDifficultyFromString(string $str) : int{ diff --git a/tests/travis/setup-php.yml b/tests/travis/setup-php.yml index e2d8aac52..ae47c2ae2 100644 --- a/tests/travis/setup-php.yml +++ b/tests/travis/setup-php.yml @@ -55,9 +55,18 @@ before_script: - make - make install - cd .. + - | + git clone https://github.com/pmmp/ext-morton.git -b 0.1.0 --depth=1 + cd ext-morton + phpize + ./configure + make + make install + cd .. - echo "extension=pthreads.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - echo "extension=chunkutils2.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - echo "extension=leveldb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - echo "extension=morton.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini cache: - leveldb-mcpe