ext-morton is now required and used for World::chunkHash() and World::chunkBlockHash()

This commit is contained in:
Dylan K. Taylor 2020-10-17 16:09:30 +01:00
parent 2d839db47e
commit 0f9d5f7011
7 changed files with 23 additions and 7 deletions

@ -1 +1 @@
Subproject commit bc8e1cf0015d9c74feaecdb5bf6c3bf9b9e80489 Subproject commit 7da8425e677c68d8884788f2917fee2804f25c5a

@ -1 +1 @@
Subproject commit 0400f85329092be8ffaaca1b6921a18fae7848e1 Subproject commit c8c0557ddf159413352de2a74a013d40fbfe3a69

View File

@ -20,6 +20,7 @@
"ext-json": "*", "ext-json": "*",
"ext-leveldb": "^0.2.1", "ext-leveldb": "^0.2.1",
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-morton": "^0.1.0",
"ext-openssl": "*", "ext-openssl": "*",
"ext-pcre": "*", "ext-pcre": "*",
"ext-phar": "*", "ext-phar": "*",

3
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "7fdb5abb5388f1e92229efff1f783d40", "content-hash": "cfc91763774445e65e366642b2efdde1",
"packages": [ "packages": [
{ {
"name": "adhocore/json-comment", "name": "adhocore/json-comment",
@ -3104,6 +3104,7 @@
"ext-json": "*", "ext-json": "*",
"ext-leveldb": "^0.2.1", "ext-leveldb": "^0.2.1",
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-morton": "^0.1.0",
"ext-openssl": "*", "ext-openssl": "*",
"ext-pcre": "*", "ext-pcre": "*",
"ext-phar": "*", "ext-phar": "*",

View File

@ -88,6 +88,7 @@ namespace pocketmine {
"json" => "JSON", "json" => "JSON",
"leveldb" => "LevelDB", "leveldb" => "LevelDB",
"mbstring" => "Multibyte String", "mbstring" => "Multibyte String",
"morton" => "morton",
"openssl" => "OpenSSL", "openssl" => "OpenSSL",
"pcre" => "PCRE", "pcre" => "PCRE",
"phar" => "Phar", "phar" => "Phar",

View File

@ -96,6 +96,9 @@ use function lcg_value;
use function max; use function max;
use function microtime; use function microtime;
use function min; use function min;
use function morton2d_decode;
use function morton2d_encode;
use function morton3d_encode;
use function mt_rand; use function mt_rand;
use function spl_object_id; use function spl_object_id;
use function strtolower; use function strtolower;
@ -268,10 +271,11 @@ class World implements ChunkManager{
private $logger; private $logger;
public static function chunkHash(int $x, int $z) : int{ 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{ 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; $shiftedY = $y - self::HALF_Y_MAX;
if($shiftedY < -512 or $shiftedY >= 512){ if($shiftedY < -512 or $shiftedY >= 512){
throw new \InvalidArgumentException("Y coordinate $y is out of range!"); 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. * Computes a small index relative to chunk base from the given coordinates.
*/ */
public static function chunkBlockHash(int $x, int $y, int $z) : int{ 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{ public static function getBlockXYZ(int $hash, ?int &$x, ?int &$y, ?int &$z) : void{
//TODO: switch this to use morton3d
$x = $hash >> 37; $x = $hash >> 37;
$y = ($hash << 27 >> 54) + self::HALF_Y_MAX; $y = ($hash << 27 >> 54) + self::HALF_Y_MAX;
$z = $hash << 37 >> 37; $z = $hash << 37 >> 37;
} }
public static function getXZ(int $hash, ?int &$x, ?int &$z) : void{ public static function getXZ(int $hash, ?int &$x, ?int &$z) : void{
$x = $hash >> 32; [$x, $z] = morton2d_decode($hash);
$z = ($hash & 0xFFFFFFFF) << 32 >> 32;
} }
public static function getDifficultyFromString(string $str) : int{ public static function getDifficultyFromString(string $str) : int{

View File

@ -55,9 +55,18 @@ before_script:
- make - make
- make install - make install
- cd .. - 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=pthreads.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- echo "extension=chunkutils2.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=leveldb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- echo "extension=morton.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
cache: cache:
- leveldb-mcpe - leveldb-mcpe