mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-04 17:06:16 +00:00
Fixed CPU leak
This commit is contained in:
@ -25,51 +25,10 @@ use pocketmine\math\Vector3;
|
||||
use pocketmine\utils\LevelException;
|
||||
|
||||
class Position extends Vector3{
|
||||
|
||||
/** @var Position[] */
|
||||
private static $positionList = [];
|
||||
private static $nextPosition = 0;
|
||||
|
||||
/** @var Level */
|
||||
public $level = null;
|
||||
|
||||
public static function clearPositions(){
|
||||
self::$nextPosition = 0;
|
||||
self::$positionList = [];
|
||||
}
|
||||
|
||||
public static function clearPositionList(){
|
||||
if(self::$nextPosition > 65536){
|
||||
self::clearVectors();
|
||||
}else{
|
||||
self::$nextPosition = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $x
|
||||
* @param $y
|
||||
* @param $z
|
||||
* @param Level $level
|
||||
*
|
||||
* @return Position
|
||||
*/
|
||||
public static function createPosition($x, $y, $z, Level $level){
|
||||
if(self::$nextPosition >= count(self::$positionList)){
|
||||
self::$positionList[] = new Position(0, 0, 0, null);
|
||||
}
|
||||
|
||||
return self::$positionList[self::$nextPosition++]->setLevel($level)->setComponents($x, $y, $z);
|
||||
}
|
||||
|
||||
public static function clonePosition(Position $pos){
|
||||
if(self::$nextPosition >= count(self::$positionList)){
|
||||
self::$positionList[] = new Position(0, 0, 0, null);
|
||||
}
|
||||
|
||||
return self::$positionList[self::$nextPosition++]->setLevel($pos->level)->setComponents($pos->x, $pos->y, $pos->z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
@ -84,7 +43,7 @@ class Position extends Vector3{
|
||||
}
|
||||
|
||||
public static function fromObject(Vector3 $pos, Level $level = null){
|
||||
return self::createPosition($pos->x, $pos->y, $pos->z, $level);
|
||||
return new Position($pos->x, $pos->y, $pos->z, $level);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user