mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
BlockFactory: minor reduction in memory usage
removing useless array and don't pre-populate with UnknownBlock objects
This commit is contained in:
parent
f27c6fcf70
commit
515e4aabc4
@ -31,8 +31,6 @@ use pocketmine\utils\MainLogger;
|
|||||||
* Manages block registration and instance creation
|
* Manages block registration and instance creation
|
||||||
*/
|
*/
|
||||||
class BlockFactory{
|
class BlockFactory{
|
||||||
/** @var \SplFixedArray<Block> */
|
|
||||||
private static $list = null;
|
|
||||||
/** @var \SplFixedArray<Block> */
|
/** @var \SplFixedArray<Block> */
|
||||||
private static $fullList = null;
|
private static $fullList = null;
|
||||||
|
|
||||||
@ -65,7 +63,6 @@ class BlockFactory{
|
|||||||
* this if you need to reset the block factory back to its original defaults for whatever reason.
|
* this if you need to reset the block factory back to its original defaults for whatever reason.
|
||||||
*/
|
*/
|
||||||
public static function init() : void{
|
public static function init() : void{
|
||||||
self::$list = new \SplFixedArray(256);
|
|
||||||
self::$fullList = new \SplFixedArray(4096);
|
self::$fullList = new \SplFixedArray(4096);
|
||||||
|
|
||||||
self::$light = new \SplFixedArray(256);
|
self::$light = new \SplFixedArray(256);
|
||||||
@ -327,12 +324,6 @@ class BlockFactory{
|
|||||||
|
|
||||||
//TODO: RESERVED6
|
//TODO: RESERVED6
|
||||||
|
|
||||||
foreach(self::$list as $id => $block){
|
|
||||||
if($block === null){
|
|
||||||
self::registerBlock(new UnknownBlock($id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var mixed[] $runtimeIdMap */
|
/** @var mixed[] $runtimeIdMap */
|
||||||
$runtimeIdMap = json_decode(file_get_contents(\pocketmine\RESOURCE_PATH . "runtimeid_table.json"), true);
|
$runtimeIdMap = json_decode(file_get_contents(\pocketmine\RESOURCE_PATH . "runtimeid_table.json"), true);
|
||||||
foreach($runtimeIdMap as $obj){
|
foreach($runtimeIdMap as $obj){
|
||||||
@ -360,8 +351,6 @@ class BlockFactory{
|
|||||||
throw new \RuntimeException("Trying to overwrite an already registered block");
|
throw new \RuntimeException("Trying to overwrite an already registered block");
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$list[$id] = clone $block;
|
|
||||||
|
|
||||||
for($meta = 0; $meta < 16; ++$meta){
|
for($meta = 0; $meta < 16; ++$meta){
|
||||||
$variant = clone $block;
|
$variant = clone $block;
|
||||||
$variant->setDamage($meta);
|
$variant->setDamage($meta);
|
||||||
@ -392,8 +381,8 @@ class BlockFactory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if(self::$fullList !== null){
|
if(self::$fullList !== null and self::$fullList[$idx = ($id << 4) | $meta] !== null){
|
||||||
$block = clone self::$fullList[($id << 4) | $meta];
|
$block = clone self::$fullList[$idx];
|
||||||
}else{
|
}else{
|
||||||
$block = new UnknownBlock($id, $meta);
|
$block = new UnknownBlock($id, $meta);
|
||||||
}
|
}
|
||||||
@ -426,7 +415,7 @@ class BlockFactory{
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isRegistered(int $id) : bool{
|
public static function isRegistered(int $id) : bool{
|
||||||
$b = self::$list[$id];
|
$b = self::$fullList[$id << 4];
|
||||||
return $b !== null and !($b instanceof UnknownBlock);
|
return $b !== null and !($b instanceof UnknownBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user