fixes, new Tile update algorithm

This commit is contained in:
Shoghi Cervantes 2014-02-27 15:12:05 +01:00
parent c9dfdc288d
commit 6bd91cf39e
8 changed files with 47 additions and 19 deletions

View File

@ -215,8 +215,23 @@ class ServerAPI{
$ob->init(); //Fails sometimes!!!
}
}
$this->loadAPI("plugin", "PluginAPI"); //fix :(
$this->plugin->init();
}
public function checkTickUpdates(){
//Update tiles that need update
if(count(Tile::$needUpdate) > 0){
foreach(Tile::$needUpdate as $id => $tile){
if($tile->update() === false){
unset(Tile::$needUpdate[$id]);
}
}
}
}
public function async(callable $callable, $params = array(), $remove = false){
@ -351,6 +366,7 @@ class ServerAPI{
$this->query = new QueryHandler();
}
CraftingRecipes::init();
$this->schedule(2, array($this, "checkTickUpdates"), array(), true);
$this->server->init();
unregister_tick_function(array($this->server, "tick"));
$this->console->__destruct();

View File

@ -562,13 +562,13 @@ class Player{
$pk = new ContainerSetDataPacket;
$pk->windowid = $id;
$pk->property = 0; //Smelting
$pk->value = floor($data->data["CookTime"]);
$pk->value = floor($data->namedtag->CookTime);
$this->dataPacket($pk);
$pk = new ContainerSetDataPacket;
$pk->windowid = $id;
$pk->property = 1; //Fire icon
$pk->value = $data->data["BurnTicks"];
$pk->value = $data->namedtag->BurnTicks;
$this->dataPacket($pk);
}
}

View File

@ -41,7 +41,6 @@ abstract class Tile extends Position{
public $closed;
public $namedtag;
private $lastUpdate;
private $scheduledUpdate;
private $server;
public static function getByID($tileID){
@ -65,7 +64,6 @@ abstract class Tile extends Position{
$this->closed = false;
$this->name = "";
$this->lastUpdate = microtime(true);
$this->scheduledUpdate = false;
$this->id = Tile::$tileCount++;
Tile::$list[$this->id] = $this;
$this->class = $this->namedtag->id;
@ -82,14 +80,19 @@ abstract class Tile extends Position{
public function update(){
return false;
}
public final function scheduleUpdate(){
Tile::$needUpdate[$this->id] = $this;
}
public function close(){
if($this->closed === false){
$this->closed = true;
unset(Tile::$list[$this->id]);
$index = PMFLevel::getIndex($this->x >> 4, $this->z >> 4);
unset($this->level->tiles[$this->id]);
unset($this->level->chunkTiles[$index][$this->id]);
unset(Tile::$needUpdate[$this->id]);
unset($this->level->tiles[$this->id]);
unset($this->level->chunkTiles[$index][$this->id]);
unset(Tile::$list[$this->id]);
$this->server->api->dhandle("tile.remove", $t);
}
}

View File

@ -29,6 +29,11 @@ class ChestTile extends SpawnableTile{
const SLOTS = 27;
public function __construct(Level $level, NBTTag_Compound $nbt){
$nbt->id = Tile::Chest;
parent::__construct($level, $nbt);
}
public function isPaired(){
if(!isset($this->namedtag->pairx) or !isset($this->namedtag->pairz)){
return false;

View File

@ -170,8 +170,8 @@ trait ContainerTileTrait{
"slotdata" => $item,
));
if($update === true and $this->scheduledUpdate === false){
$this->update();
if($update === true){
$this->scheduleUpdate();
}
return true;
}

View File

@ -29,6 +29,7 @@ class FurnaceTile extends Tile{
const SLOTS = 3;
public function __construct(Level $level, NBTTag_Compound $nbt){
$nbt->id = Tile::Furnace;
parent::__construct($level, $nbt);
if(!isset($this->namedtag->BurnTime) or $this->namedtag->BurnTime < 0){
$this->namedtag->BurnTime = 0;
@ -41,14 +42,16 @@ class FurnaceTile extends Tile{
$this->namedtag->BurnTicks = 0;
}
if($this->namedtag->BurnTime > 0){
$this->update();
$this->scheduleUpdate();
}
}
public function update(){
if($this->closed === true){
return false;
}
}
$ret = false;
$fuel = $this->getSlot(1);
$raw = $this->getSlot(0);
@ -92,8 +95,7 @@ class FurnaceTile extends Tile{
}else{
$this->namedtag->CookTime = 0;
}
$this->server->schedule(2, array($this, "update"));
$this->scheduledUpdate = true;
$ret = true;
}else{
$current = $this->level->getBlock($this);
if($current->getID() === BURNING_FURNACE){
@ -102,11 +104,11 @@ class FurnaceTile extends Tile{
$this->namedtag->CookTime = 0;
$this->namedtag->BurnTime = 0;
$this->namedtag->BurnTicks = 0;
$this->scheduledUpdate = false;
}
$this->server->handle("tile.update", $this);
$this->lastUpdate = microtime(true);
$this->lastUpdate = microtime(true);
return $ret;
}
}

View File

@ -24,11 +24,13 @@ require_once("SpawnableTile.php");
/***REM_END***/
class SignTile extends SpawnableTile{
public function __construct(Level $level, NBTTag_Compound $nbt){
$nbt->id = Tile::Sign;
parent::__construct($level, $nbt);
}
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){
if($this->class !== Tile::SIGN){
return false;
}
$this->namedtag->Text1 = $line1;
$this->namedtag->Text2 = $line2;
$this->namedtag->Text3 = $line3;

View File

@ -306,7 +306,7 @@ class Level{
}
public function getTile(Vector3 $pos){
if($pos instanceof Position and $pos->level->getName() !== $this->getName()){
if($pos instanceof Position and $pos->level !== $this){
return false;
}
$tiles = $this->getChunkTiles($pos->x >> 4, $pos->z >> 4);