From a7944502cdf7f9f1645e645741c3543168f40393 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 12 Jul 2014 19:27:51 +0200 Subject: [PATCH] Added small things --- src/pocketmine/PocketMine.php | 2 +- src/pocketmine/Server.php | 5 +++- src/pocketmine/level/Level.php | 11 +++++-- src/pocketmine/level/format/anvil/Anvil.php | 14 +++++++-- .../scheduler/PHPGarbageCollectionTask.php | 30 +++++++++++++++++++ src/pocketmine/scheduler/ServerScheduler.php | 2 +- 6 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 src/pocketmine/scheduler/PHPGarbageCollectionTask.php diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 6c6639ac3..7e44e9699 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -135,7 +135,7 @@ namespace pocketmine { } } - gc_enable(); + gc_disable(); error_reporting(E_ALL | E_STRICT); ini_set("allow_url_fopen", 1); ini_set("display_errors", 1); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 158e5cc8f..3857bb578 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -73,6 +73,7 @@ use pocketmine\plugin\Plugin; use pocketmine\plugin\PluginLoadOrder; use pocketmine\plugin\PluginManager; use pocketmine\scheduler\CallbackTask; +use pocketmine\scheduler\PHPGarbageCollectionTask; use pocketmine\scheduler\SendUsageTask; use pocketmine\scheduler\ServerScheduler; use pocketmine\tile\Tile; @@ -1521,9 +1522,11 @@ class Server{ } if($this->getProperty("chunk-gc.period-in-ticks", 600) > 0){ - $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask(array($this, "doLevelGC")), $this->getProperty("chunk-gc.period-in-ticks", 600), $this->getProperty("chunk-gc.period-in-ticks", 600)); + $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "doLevelGC"]), $this->getProperty("chunk-gc.period-in-ticks", 600), $this->getProperty("chunk-gc.period-in-ticks", 600)); } + $this->scheduler->scheduleRepeatingTask(new PHPGarbageCollectionTask(), 100); + $this->enablePlugins(PluginLoadOrder::POSTWORLD); } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 383aed897..a2fa2d341 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -341,7 +341,7 @@ class Level implements ChunkManager, Metadatable{ */ public function freeAllChunks(Player $player){ foreach($this->usedChunks as $i => $c){ - unset($this->usedChunks[$i][spl_object_hash($player)]); + unset($this->usedChunks[$i][$player->getID()]); } } @@ -354,7 +354,7 @@ class Level implements ChunkManager, Metadatable{ * @param Player $player */ public function freeChunk($X, $Z, Player $player){ - unset($this->usedChunks[Level::chunkHash($X, $Z)][$player->getID()]); + unset($this->usedChunks[$index = Level::chunkHash($X, $Z)][$player->getID()]); $this->unloadChunkRequest($X, $Z, true); } @@ -1523,6 +1523,7 @@ class Level implements ChunkManager, Metadatable{ $this->timings->doChunkUnload->startTiming(); $this->provider->unloadChunk($x, $z, $safe); + unset($this->usedChunks[Level::chunkHash($x, $z)]); Cache::remove("world:" . $this->getID() . ":$x:$z"); $this->timings->doChunkUnload->stopTiming(); @@ -1682,7 +1683,7 @@ class Level implements ChunkManager, Metadatable{ } public function regenerateChunk($x, $z){ - $this->unloadChunk($x, $z); + $this->unloadChunk($x, $z, false); $this->cancelUnloadChunkRequest($x, $z); @@ -1714,6 +1715,10 @@ class Level implements ChunkManager, Metadatable{ if(count($c) === 0){ Level::getXZ($i, $X, $Z); if(!$this->isSpawnChunk($X, $Z)){ + if($this->getAutoSave()){ + $this->provider->saveChunk($X, $Z); + } + $this->unloadChunk($X, $Z, true); } } diff --git a/src/pocketmine/level/format/anvil/Anvil.php b/src/pocketmine/level/format/anvil/Anvil.php index 4f0bbd131..f866c6c96 100644 --- a/src/pocketmine/level/format/anvil/Anvil.php +++ b/src/pocketmine/level/format/anvil/Anvil.php @@ -130,8 +130,8 @@ class Anvil extends BaseLevelProvider{ } public function unloadChunk($x, $z, $safe = true){ + $chunk = $this->getChunk($x, $z, false); if($safe === true and $this->isChunkLoaded($x, $z)){ - $chunk = $this->getChunk($x, $z); foreach($chunk->getEntities() as $entity){ if($entity instanceof Player){ return false; @@ -139,7 +139,17 @@ class Anvil extends BaseLevelProvider{ } } - unset($this->chunks[Level::chunkHash($x, $z)]); + foreach($chunk->getEntities() as $entity){ + $entity->close(); + } + + foreach($chunk->getTiles() as $tile){ + $tile->close(); + } + + $this->chunks[$index = Level::chunkHash($x, $z)] = null; + + unset($this->chunks[$index]); return true; } diff --git a/src/pocketmine/scheduler/PHPGarbageCollectionTask.php b/src/pocketmine/scheduler/PHPGarbageCollectionTask.php new file mode 100644 index 000000000..3adfabffe --- /dev/null +++ b/src/pocketmine/scheduler/PHPGarbageCollectionTask.php @@ -0,0 +1,30 @@ +handle(new TaskHandler(!($task instanceof PluginTask) ? "Scheduler" : null, $task, $this->nextId(), $delay, $period)); + return $this->handle(new TaskHandler(get_class($task), $task, $this->nextId(), $delay, $period)); } private function handle(TaskHandler $handler){