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(count($args) === 0){
if($sender instanceof Player){ if($sender instanceof Player){
$level = $sender->getLevel(); $level = $sender->getLevel();
$pos = Vector3::cloneVector($sender)->round(); $pos = Vector3::cloneVector($sender);
$pos = $pos->round();
}else{ }else{
$sender->sendMessage(TextFormat::RED . "You can only perform this command as a player"); $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(){ 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){ if($block instanceof Water){
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
@ -787,7 +788,8 @@ abstract class Entity extends Location implements Metadatable{
} }
public function isInsideOfSolid(){ 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(); $bb = $block->getBoundingBox();

View File

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

View File

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

View File

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

View File

@ -24,8 +24,8 @@ namespace pocketmine\math;
class Vector3{ class Vector3{
/** @var Vector3[] */ /** @var Vector3[] */
private static $vectorList = []; public static $vectorList = [];
private static $nextVector = 0; public static $nextVector = 0;
const SIDE_DOWN = 0; const SIDE_DOWN = 0;
const SIDE_UP = 1; const SIDE_UP = 1;
@ -45,15 +45,15 @@ class Vector3{
} }
public static function clearVectors(){ public static function clearVectors(){
self::$nextVector = 0; Vector3::$nextVector = 0;
self::$vectorList = []; Vector3::$vectorList = [];
} }
public static function clearVectorList(){ public static function clearVectorList(){
if(self::$nextVector > 65536){ if(Vector3::$nextVector > 65536){
self::clearVectors(); Vector3::clearVectors();
}else{ }else{
self::$nextVector = 0; Vector3::$nextVector = 0;
} }
} }
@ -65,11 +65,11 @@ class Vector3{
* @return Vector3 * @return Vector3
*/ */
public static function createVector($x, $y, $z){ public static function createVector($x, $y, $z){
if(self::$nextVector >= count(self::$vectorList)){ if(Vector3::$nextVector >= count(Vector3::$vectorList)){
self::$vectorList[] = new Vector3(0, 0, 0); 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 * @return Vector3
*/ */
public static function cloneVector(Vector3 $vector){ public static function cloneVector(Vector3 $vector){
if(self::$nextVector >= count(self::$vectorList)){ if(Vector3::$nextVector >= count(Vector3::$vectorList)){
self::$vectorList[] = new Vector3(0, 0, 0); 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(){ public function getX(){
@ -138,9 +138,9 @@ class Vector3{
*/ */
public function add($x, $y = 0, $z = 0){ public function add($x, $y = 0, $z = 0){
if($x instanceof Vector3){ 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{ }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){ 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){ 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(){ 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(){ public function floor(){
$x = (int) $this->x; $x = (int) $this->x;
$y = (int) $this->y; $y = (int) $this->y;
$z = (int) $this->z; $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(){ 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(){ 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){ public function getSide($side, $step = 1){
switch((int) $side){ switch((int) $side){
case self::SIDE_DOWN: case Vector3::SIDE_DOWN:
return self::createVector($this->x, $this->y - $step, $this->z); return Vector3::createVector($this->x, $this->y - $step, $this->z);
case self::SIDE_UP: case Vector3::SIDE_UP:
return self::createVector($this->x, $this->y + $step, $this->z); return Vector3::createVector($this->x, $this->y + $step, $this->z);
case self::SIDE_NORTH: case Vector3::SIDE_NORTH:
return self::createVector($this->x, $this->y, $this->z - $step); return Vector3::createVector($this->x, $this->y, $this->z - $step);
case self::SIDE_SOUTH: case Vector3::SIDE_SOUTH:
return self::createVector($this->x, $this->y, $this->z + $step); return Vector3::createVector($this->x, $this->y, $this->z + $step);
case self::SIDE_WEST: case Vector3::SIDE_WEST:
return self::createVector($this->x - $step, $this->y, $this->z); return Vector3::createVector($this->x - $step, $this->y, $this->z);
case self::SIDE_EAST: case Vector3::SIDE_EAST:
return self::createVector($this->x + $step, $this->y, $this->z); return Vector3::createVector($this->x + $step, $this->y, $this->z);
default: default:
return $this; return $this;
} }
@ -207,18 +207,18 @@ class Vector3{
public static function getOppositeSide($side){ public static function getOppositeSide($side){
switch((int) $side){ switch((int) $side){
case self::SIDE_DOWN: case Vector3::SIDE_DOWN:
return self::SIDE_UP; return Vector3::SIDE_UP;
case self::SIDE_UP: case Vector3::SIDE_UP:
return self::SIDE_DOWN; return Vector3::SIDE_DOWN;
case self::SIDE_NORTH: case Vector3::SIDE_NORTH:
return self::SIDE_SOUTH; return Vector3::SIDE_SOUTH;
case self::SIDE_SOUTH: case Vector3::SIDE_SOUTH:
return self::SIDE_NORTH; return Vector3::SIDE_NORTH;
case self::SIDE_WEST: case Vector3::SIDE_WEST:
return self::SIDE_EAST; return Vector3::SIDE_EAST;
case self::SIDE_EAST: case Vector3::SIDE_EAST:
return self::SIDE_WEST; return Vector3::SIDE_WEST;
default: default:
return -1; return -1;
} }
@ -259,7 +259,7 @@ class Vector3{
return $this->divide($len); return $this->divide($len);
} }
return self::createVector(0, 0, 0); return Vector3::createVector(0, 0, 0);
} }
public function dot(Vector3 $v){ public function dot(Vector3 $v){
@ -267,7 +267,7 @@ class Vector3{
} }
public function cross(Vector3 $v){ public function cross(Vector3 $v){
return self::createVector( return Vector3::createVector(
$this->y * $v->z - $this->z * $v->y, $this->y * $v->z - $this->z * $v->y,
$this->z * $v->x - $this->x * $v->z, $this->z * $v->x - $this->x * $v->z,
$this->x * $v->y - $this->y * $v->x $this->x * $v->y - $this->y * $v->x
@ -297,7 +297,7 @@ class Vector3{
if($f < 0 or $f > 1){ if($f < 0 or $f > 1){
return null; return null;
}else{ }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){ if($f < 0 or $f > 1){
return null; return null;
}else{ }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){ if($f < 0 or $f > 1){
return null; return null;
}else{ }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; $secondPosition = 0;
$thirdPosition = 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){ if($this->getXLength($direction) > $mainDirection){
$this->mainFace = $this->getXFace($direction); $this->mainFace = $this->getXFace($direction);