Updated to receive new optimizations

This commit is contained in:
Shoghi Cervantes 2014-10-30 16:02:48 +01:00
parent 6e8e2a79dd
commit 57d1847c50
7 changed files with 65 additions and 57 deletions

View File

@ -46,7 +46,8 @@ class SetWorldSpawnCommand extends VanillaCommand{
if(count($args) === 0){
if($sender instanceof Player){
$level = $sender->getLevel();
$pos = Vector3::cloneVector($sender)->round();
$pos = Vector3::cloneVector($sender);
$pos = $pos->round();
}else{
$sender->sendMessage(TextFormat::RED . "You can only perform this command as a player");

View File

@ -776,7 +776,8 @@ abstract class Entity extends Location implements Metadatable{
}
public function isInsideOfWater(){
$block = $this->level->getBlock(Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor());
$pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z);
$block = $this->level->getBlock($pos->floor());
if($block instanceof Water){
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
@ -787,7 +788,8 @@ abstract class Entity extends Location implements Metadatable{
}
public function isInsideOfSolid(){
$block = $this->level->getBlock(Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor());
$pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z);
$block = $this->level->getBlock($pos->floor());
$bb = $block->getBoundingBox();

View File

@ -90,7 +90,8 @@ class FallingSand extends Entity{
if(!$this->dead){
if($this->ticksLived === 1){
$block = $this->level->getBlock($pos = Vector3::cloneVector($this)->floor());
$pos = Vector3::cloneVector($this);
$block = $this->level->getBlock($pos->floor());
if($block->getID() != $this->blockId){
$this->kill();
return true;
@ -109,7 +110,8 @@ class FallingSand extends Entity{
$this->motionY *= 1 - $this->drag;
$this->motionZ *= $friction;
$pos = Vector3::cloneVector($this)->floor();
$pos = Vector3::cloneVector($this);
$pos = $pos->floor();
if($this->onGround){
$this->kill();

View File

@ -130,7 +130,8 @@ class Explosion{
public function explodeB(){
$send = [];
$source = Vector3::cloneVector($this->source)->floor();
$source = Vector3::cloneVector($this->source);
$source = $source->floor();
$yield = (1 / $this->size) * 100;
if($this->what instanceof Entity){

View File

@ -95,6 +95,7 @@ use pocketmine\utils\LevelException;
use pocketmine\utils\ReversePriorityQueue;
use pocketmine\utils\TextFormat;
#include <rules/Level.h>
class Level implements ChunkManager, Metadatable{

View File

@ -24,8 +24,8 @@ namespace pocketmine\math;
class Vector3{
/** @var Vector3[] */
private static $vectorList = [];
private static $nextVector = 0;
public static $vectorList = [];
public static $nextVector = 0;
const SIDE_DOWN = 0;
const SIDE_UP = 1;
@ -45,15 +45,15 @@ class Vector3{
}
public static function clearVectors(){
self::$nextVector = 0;
self::$vectorList = [];
Vector3::$nextVector = 0;
Vector3::$vectorList = [];
}
public static function clearVectorList(){
if(self::$nextVector > 65536){
self::clearVectors();
if(Vector3::$nextVector > 65536){
Vector3::clearVectors();
}else{
self::$nextVector = 0;
Vector3::$nextVector = 0;
}
}
@ -65,11 +65,11 @@ class Vector3{
* @return Vector3
*/
public static function createVector($x, $y, $z){
if(self::$nextVector >= count(self::$vectorList)){
self::$vectorList[] = new Vector3(0, 0, 0);
if(Vector3::$nextVector >= count(Vector3::$vectorList)){
Vector3::$vectorList[] = new Vector3(0, 0, 0);
}
return self::$vectorList[self::$nextVector++]->setComponents($x, $y, $z);
return Vector3::$vectorList[Vector3::$nextVector++]->setComponents($x, $y, $z);
}
/**
@ -78,11 +78,11 @@ class Vector3{
* @return Vector3
*/
public static function cloneVector(Vector3 $vector){
if(self::$nextVector >= count(self::$vectorList)){
self::$vectorList[] = new Vector3(0, 0, 0);
if(Vector3::$nextVector >= count(Vector3::$vectorList)){
Vector3::$vectorList[] = new Vector3(0, 0, 0);
}
return self::$vectorList[self::$nextVector++]->setComponents($vector->x, $vector->y, $vector->z);
return Vector3::$vectorList[Vector3::$nextVector++]->setComponents($vector->x, $vector->y, $vector->z);
}
public function getX(){
@ -138,9 +138,9 @@ class Vector3{
*/
public function add($x, $y = 0, $z = 0){
if($x instanceof Vector3){
return self::createVector($this->x + $x->x, $this->y + $x->y, $this->z + $x->z);
return Vector3::createVector($this->x + $x->x, $this->y + $x->y, $this->z + $x->z);
}else{
return self::createVector($this->x + $x, $this->y + $y, $this->z + $z);
return Vector3::createVector($this->x + $x, $this->y + $y, $this->z + $z);
}
}
@ -160,46 +160,46 @@ class Vector3{
}
public function multiply($number){
return self::createVector($this->x * $number, $this->y * $number, $this->z * $number);
return Vector3::createVector($this->x * $number, $this->y * $number, $this->z * $number);
}
public function divide($number){
return self::createVector($this->x / $number, $this->y / $number, $this->z / $number);
return Vector3::createVector($this->x / $number, $this->y / $number, $this->z / $number);
}
public function ceil(){
return self::createVector((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1));
return Vector3::createVector((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1));
}
public function floor(){
$x = (int) $this->x;
$y = (int) $this->y;
$z = (int) $this->z;
return new Vector3($this->x >= $x ? $x : $x - 1, $this->y >= $y ? $y : $y - 1, $this->z >= $z ? $z : $z - 1);
return Vector3::createVector($this->x >= $x ? $x : $x - 1, $this->y >= $y ? $y : $y - 1, $this->z >= $z ? $z : $z - 1);
}
public function round(){
return new Vector3(round($this->x), round($this->y), round($this->z));
return Vector3::createVector(round($this->x), round($this->y), round($this->z));
}
public function abs(){
return new Vector3(abs($this->x), abs($this->y), abs($this->z));
return Vector3::createVector(abs($this->x), abs($this->y), abs($this->z));
}
public function getSide($side, $step = 1){
switch((int) $side){
case self::SIDE_DOWN:
return self::createVector($this->x, $this->y - $step, $this->z);
case self::SIDE_UP:
return self::createVector($this->x, $this->y + $step, $this->z);
case self::SIDE_NORTH:
return self::createVector($this->x, $this->y, $this->z - $step);
case self::SIDE_SOUTH:
return self::createVector($this->x, $this->y, $this->z + $step);
case self::SIDE_WEST:
return self::createVector($this->x - $step, $this->y, $this->z);
case self::SIDE_EAST:
return self::createVector($this->x + $step, $this->y, $this->z);
case Vector3::SIDE_DOWN:
return Vector3::createVector($this->x, $this->y - $step, $this->z);
case Vector3::SIDE_UP:
return Vector3::createVector($this->x, $this->y + $step, $this->z);
case Vector3::SIDE_NORTH:
return Vector3::createVector($this->x, $this->y, $this->z - $step);
case Vector3::SIDE_SOUTH:
return Vector3::createVector($this->x, $this->y, $this->z + $step);
case Vector3::SIDE_WEST:
return Vector3::createVector($this->x - $step, $this->y, $this->z);
case Vector3::SIDE_EAST:
return Vector3::createVector($this->x + $step, $this->y, $this->z);
default:
return $this;
}
@ -207,18 +207,18 @@ class Vector3{
public static function getOppositeSide($side){
switch((int) $side){
case self::SIDE_DOWN:
return self::SIDE_UP;
case self::SIDE_UP:
return self::SIDE_DOWN;
case self::SIDE_NORTH:
return self::SIDE_SOUTH;
case self::SIDE_SOUTH:
return self::SIDE_NORTH;
case self::SIDE_WEST:
return self::SIDE_EAST;
case self::SIDE_EAST:
return self::SIDE_WEST;
case Vector3::SIDE_DOWN:
return Vector3::SIDE_UP;
case Vector3::SIDE_UP:
return Vector3::SIDE_DOWN;
case Vector3::SIDE_NORTH:
return Vector3::SIDE_SOUTH;
case Vector3::SIDE_SOUTH:
return Vector3::SIDE_NORTH;
case Vector3::SIDE_WEST:
return Vector3::SIDE_EAST;
case Vector3::SIDE_EAST:
return Vector3::SIDE_WEST;
default:
return -1;
}
@ -259,7 +259,7 @@ class Vector3{
return $this->divide($len);
}
return self::createVector(0, 0, 0);
return Vector3::createVector(0, 0, 0);
}
public function dot(Vector3 $v){
@ -267,7 +267,7 @@ class Vector3{
}
public function cross(Vector3 $v){
return self::createVector(
return Vector3::createVector(
$this->y * $v->z - $this->z * $v->y,
$this->z * $v->x - $this->x * $v->z,
$this->x * $v->y - $this->y * $v->x
@ -297,7 +297,7 @@ class Vector3{
if($f < 0 or $f > 1){
return null;
}else{
return self::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
return Vector3::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
}
}
@ -324,7 +324,7 @@ class Vector3{
if($f < 0 or $f > 1){
return null;
}else{
return self::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
return Vector3::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
}
}
@ -351,7 +351,7 @@ class Vector3{
if($f < 0 or $f > 1){
return null;
}else{
return self::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
return Vector3::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
}
}

View File

@ -71,7 +71,8 @@ class BlockIterator implements \Iterator{
$secondPosition = 0;
$thirdPosition = 0;
$startBlock = $this->level->getBlock(Vector3::createVector($startClone->x, $startClone->y, $startClone->z)->floor());
$pos = Vector3::createVector($startClone->x, $startClone->y, $startClone->z);
$startBlock = $this->level->getBlock($pos->floor());
if($this->getXLength($direction) > $mainDirection){
$this->mainFace = $this->getXFace($direction);