Improved global block cache

This commit is contained in:
Shoghi Cervantes 2014-10-12 17:02:27 +02:00
parent 96b61fbb92
commit 8472349caf
3 changed files with 11 additions and 11 deletions

View File

@ -471,12 +471,11 @@ abstract class Entity extends Position implements Metadatable{
$this->justCreated = false;
$isPlayer = $this instanceof Player;
if($this->dead === true and !$isPlayer){
$this->close();
Timings::$tickEntityTimer->stopTiming();
return false;
}elseif($this->dead === true){
if($this->dead === true){
$this->despawnFromAll();
if(!$isPlayer){
$this->close();
}
Timings::$tickEntityTimer->stopTiming();
return false;
}

View File

@ -21,6 +21,7 @@
namespace pocketmine\level;
use pocketmine\block\Air;
use pocketmine\block\Block;
use pocketmine\block\TNT;
use pocketmine\entity\Entity;
@ -98,10 +99,9 @@ class Explosion{
if($vBlock->y < 0 or $vBlock->y > 127){
break;
}
$blockID = $this->level->getBlockIdAt($vBlock->x, $vBlock->y, $vBlock->z);
$block = $this->level->getBlock($vBlock);
if($blockID > 0){
$block = Block::get($blockID, 0);
if(!($block instanceof Air)){
$block->x = $vBlock->x;
$block->y = $vBlock->y;
$block->z = $vBlock->z;

View File

@ -872,14 +872,15 @@ class Level implements ChunkManager, Metadatable{
* Gets the Block object on the Vector3 location
*
* @param Vector3 $pos
* @param boolean $cached
*
* @return Block
*/
public function getBlock(Vector3 $pos){
public function getBlock(Vector3 $pos, $cached = true){
$blockId = 0;
$meta = 0;
$index = "{$pos->x}:{$pos->y}:{$pos->z}";
if(isset($this->blockCache[$index])){
if($cached and isset($this->blockCache[$index])){
return $this->blockCache[$index];
}elseif($pos->y >= 0 and $pos->y < 128 and ($chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, true)) !== null){
$chunk->getBlock($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f, $blockId, $meta);
@ -891,7 +892,7 @@ class Level implements ChunkManager, Metadatable{
$air->y = $pos->y;
$air->z = $pos->z;
$air->level = $this;
return $air;
return $this->blockCache[$index] = $air;
}
return $this->blockCache[$index] = Block::get($blockId, $meta, new Position($pos->x, $pos->y, $pos->z, $this));