From 0d775f8731c4183adef4fd5bc1dbc4d06b29d844 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 23 Mar 2021 22:21:57 +0000 Subject: [PATCH] Require ext-chunkutils2 at ^0.2.0 --- composer.json | 2 +- composer.lock | 4 +- src/PocketMine.php | 16 ++++++ src/world/format/LightArray.php | 91 --------------------------------- tests/gh-actions/build.sh | 2 +- 5 files changed, 20 insertions(+), 95 deletions(-) delete mode 100644 src/world/format/LightArray.php diff --git a/composer.json b/composer.json index 893b7c364..f10787b86 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "require": { "php": "^7.4 || ^8.0", "php-64bit": "*", - "ext-chunkutils2": "^0.1.0", + "ext-chunkutils2": "^0.2.0", "ext-crypto": "^0.3.1", "ext-ctype": "*", "ext-curl": "*", diff --git a/composer.lock b/composer.lock index 1479b1827..cc1656679 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": "824d613db4986bce5882e3460ef32826", + "content-hash": "7846da3098ad1a3e694ed3dfa5eedda3", "packages": [ { "name": "adhocore/json-comment", @@ -3460,7 +3460,7 @@ "platform": { "php": "^7.4 || ^8.0", "php-64bit": "*", - "ext-chunkutils2": "^0.1.0", + "ext-chunkutils2": "^0.2.0", "ext-crypto": "^0.3.1", "ext-ctype": "*", "ext-curl": "*", diff --git a/src/PocketMine.php b/src/PocketMine.php index 09908d97d..b154a8f12 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -33,6 +33,12 @@ namespace pocketmine { use pocketmine\utils\Terminal; use pocketmine\utils\Timezone; use pocketmine\wizard\SetupWizard; + use function extension_loaded; + use function phpversion; + use function preg_match; + use function preg_quote; + use function strpos; + use function version_compare; require_once __DIR__ . '/VersionInfo.php'; @@ -121,6 +127,16 @@ namespace pocketmine { } } + $chunkutils2_version = phpversion("chunkutils2"); + $wantedVersionLock = "0.2"; + $wantedVersionMin = "$wantedVersionLock.0"; + if($chunkutils2_version !== false && ( + version_compare($chunkutils2_version, $wantedVersionMin) < 0 || + preg_match("/^" . preg_quote($wantedVersionLock, "/") . "\.\d+$/", $chunkutils2_version) === 0 //lock in at ^0.2, optionally at a patch release + )){ + $messages[] = "chunkutils2 ^$wantedVersionMin is required, while you have $chunkutils2_version."; + } + if(extension_loaded("pocketmine")){ $messages[] = "The native PocketMine extension is no longer supported."; } diff --git a/src/world/format/LightArray.php b/src/world/format/LightArray.php deleted file mode 100644 index 83b1a17dc..000000000 --- a/src/world/format/LightArray.php +++ /dev/null @@ -1,91 +0,0 @@ -data = $payload; - $this->collectGarbage(); - } - - public static function fill(int $level) : self{ - if($level === 0){ - return new self(self::ZERO); - } - if($level === 15){ - return new self(self::FIFTEEN); - } - return new self(str_repeat(chr(($level & 0x0f) | ($level << 4)), 2048)); - } - - public function get(int $x, int $y, int $z) : int{ - return (ord($this->data[($x << 7) | ($z << 3) | ($y >> 1)]) >> (($y & 1) << 2)) & 0xf; - } - - public function set(int $x, int $y, int $z, int $level) : void{ - $i = ($x << 7) | ($z << 3) | ($y >> 1); - - $shift = ($y & 1) << 2; - $byte = ord($this->data[$i]); - $this->data[$i] = chr(($byte & ~(0xf << $shift)) | (($level & 0xf) << $shift)); - } - - public function collectGarbage() : void{ - /* - * This strange looking code is designed to exploit PHP's copy-on-write behaviour. Assigning will copy a - * reference to the const instead of duplicating the whole string. The string will only be duplicated when - * modified, which is perfect for this purpose. - */ - if($this->data === self::ZERO){ - $this->data = self::ZERO; - }elseif($this->data === self::FIFTEEN){ - $this->data = self::FIFTEEN; - } - } - - public function getData() : string{ - return $this->data; - } - - public function __wakeup(){ - //const refs aren't preserved when unserializing - $this->collectGarbage(); - } -} diff --git a/tests/gh-actions/build.sh b/tests/gh-actions/build.sh index 9355111e8..da7d20aa8 100755 --- a/tests/gh-actions/build.sh +++ b/tests/gh-actions/build.sh @@ -53,7 +53,7 @@ PHP_BUILD_INSTALL_EXTENSION="\ pthreads=@acc6e52b2144c61c434b62a3cb680d537e06828e \ yaml=2.2.1 \ leveldb=@60763a09bf5c7a10376d16e25b078b99a35c5c37 \ -chunkutils2=@7aec31a9dfc83ddead8870dc0a29159596939680 \ +chunkutils2=@0.2.0 \ morton=@0.1.2 \ igbinary=3.2.1 \ " PHP_BUILD_ZTS_ENABLE=on PHP_BUILD_CONFIGURE_OPTS='--with-gmp' ./bin/php-build "$VERSION" "$INSTALL_DIR" || exit 1