mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
removed advanced cache
This commit is contained in:
parent
1bbe5c7582
commit
80d78faecd
5 changed files with 3 additions and 63 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class QueryAPI{
|
class QueryAPI{
|
||||||
|
|
||||||
public static $NOT_FOUND_VALUE;
|
public static $NOT_FOUND_VALUE; //TODO just use null
|
||||||
private $queryData;
|
private $queryData;
|
||||||
private $server;
|
private $server;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,11 +143,8 @@ class ServerAPI{
|
||||||
Entity::$allowedAI = $this->getProperty("enable-mob-ai", true);
|
Entity::$allowedAI = $this->getProperty("enable-mob-ai", true);
|
||||||
//Load advanced properties
|
//Load advanced properties
|
||||||
define("DEBUG", $this->getProperty("debug", 1));
|
define("DEBUG", $this->getProperty("debug", 1));
|
||||||
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));
|
define("ADVANCED_CACHE", false);
|
||||||
//define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s
|
//define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s
|
||||||
if(ADVANCED_CACHE == true){
|
|
||||||
console("[INFO] Advanced cache enabled");
|
|
||||||
}
|
|
||||||
MobSpawner::$spawnAnimals = $this->getProperty("spawn-animals");
|
MobSpawner::$spawnAnimals = $this->getProperty("spawn-animals");
|
||||||
MobSpawner::$spawnMobs = $this->getProperty("spawn-mobs");
|
MobSpawner::$spawnMobs = $this->getProperty("spawn-mobs");
|
||||||
if($this->getProperty("upnp-forwarding") == true){
|
if($this->getProperty("upnp-forwarding") == true){
|
||||||
|
|
|
||||||
|
|
@ -439,7 +439,6 @@ class PocketMinecraftServer{
|
||||||
}
|
}
|
||||||
$this->schedule(20 * 15, [$this, "checkTicks"], [], true);
|
$this->schedule(20 * 15, [$this, "checkTicks"], [], true);
|
||||||
$this->schedule(20 * 60, [$this, "checkMemory"], [], true);
|
$this->schedule(20 * 60, [$this, "checkMemory"], [], true);
|
||||||
$this->schedule(20 * 45, "Cache::cleanup", [], true);
|
|
||||||
$this->schedule(20, [$this, "asyncOperationChecker"], [], true);
|
$this->schedule(20, [$this, "asyncOperationChecker"], [], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -488,7 +487,7 @@ class PocketMinecraftServer{
|
||||||
} elseif($this->tick() > 0){
|
} elseif($this->tick() > 0){
|
||||||
$lastLoop = 0;
|
$lastLoop = 0;
|
||||||
} else{
|
} else{
|
||||||
++ $lastLoop;
|
++$lastLoop;
|
||||||
if($lastLoop < 16){
|
if($lastLoop < 16){
|
||||||
usleep(1);
|
usleep(1);
|
||||||
} elseif($lastLoop < 128){
|
} elseif($lastLoop < 128){
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class Cache{
|
|
||||||
|
|
||||||
public static $cached = [];
|
|
||||||
|
|
||||||
public static function add($identifier, $blob, $minTTL = 30){
|
|
||||||
self::$cached[$identifier] = [$blob, microtime(true) + $minTTL, $minTTL];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function get($identifier){
|
|
||||||
if(isset(self::$cached[$identifier])){
|
|
||||||
self::$cached[$identifier][1] = microtime(true) + self::$cached[$identifier][2];
|
|
||||||
return self::$cached[$identifier][0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function exists($identifier){
|
|
||||||
return isset(self::$cached[$identifier]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function remove($identifier){
|
|
||||||
unset(self::$cached[$identifier]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function cleanup(){
|
|
||||||
$time = microtime(true);
|
|
||||||
foreach(self::$cached as $index => $data){
|
|
||||||
if($data[1] < $time){
|
|
||||||
unset(self::$cached[$index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -292,9 +292,6 @@ class Level{
|
||||||
}
|
}
|
||||||
$block->position($pos);
|
$block->position($pos);
|
||||||
$i = ($pos->x >> 4) . ":" . ($pos->y >> 4) . ":" . ($pos->z >> 4);
|
$i = ($pos->x >> 4) . ":" . ($pos->y >> 4) . ":" . ($pos->z >> 4);
|
||||||
if(ADVANCED_CACHE == true){
|
|
||||||
Cache::remove("world:{$this->name}:" . ($pos->x >> 4) . ":" . ($pos->z >> 4));
|
|
||||||
}
|
|
||||||
if(!isset($this->changedBlocks[$i])){
|
if(!isset($this->changedBlocks[$i])){
|
||||||
$this->changedBlocks[$i] = [];
|
$this->changedBlocks[$i] = [];
|
||||||
$this->changedCount[$i] = 0;
|
$this->changedCount[$i] = 0;
|
||||||
|
|
@ -451,9 +448,6 @@ class Level{
|
||||||
$this->changedBlocks[$i] = [];
|
$this->changedBlocks[$i] = [];
|
||||||
$this->changedCount[$i] = 0;
|
$this->changedCount[$i] = 0;
|
||||||
}
|
}
|
||||||
if(ADVANCED_CACHE == true){
|
|
||||||
Cache::remove("world:{$this->name}:" . ($pos->x >> 4) . ":" . ($pos->z >> 4));
|
|
||||||
}
|
|
||||||
$this->changedBlocks[$i][] = [$block->x, $block->y, $block->z, $block->id, $block->getMetadata()];
|
$this->changedBlocks[$i][] = [$block->x, $block->y, $block->z, $block->id, $block->getMetadata()];
|
||||||
++$this->changedCount[$i];
|
++$this->changedCount[$i];
|
||||||
}
|
}
|
||||||
|
|
@ -482,9 +476,6 @@ class Level{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->changedCount[$X . ":" . $Y . ":" . $Z] = 4096;
|
$this->changedCount[$X . ":" . $Y . ":" . $Z] = 4096;
|
||||||
if(ADVANCED_CACHE == true){
|
|
||||||
Cache::remove("world:{$this->name}:$X:$Z");
|
|
||||||
}
|
|
||||||
return $this->level->setMiniChunk($X, $Z, $Y, $data);
|
return $this->level->setMiniChunk($X, $Z, $Y, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -503,7 +494,6 @@ class Level{
|
||||||
if($force !== true and $this->isSpawnChunk($X, $Z)){
|
if($force !== true and $this->isSpawnChunk($X, $Z)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Cache::remove("world:{$this->name}:$X:$Z");
|
|
||||||
return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
|
return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -511,13 +501,6 @@ class Level{
|
||||||
if(!isset($this->level)){
|
if(!isset($this->level)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(ADVANCED_CACHE == true and $Yndex == 0xff){
|
|
||||||
$identifier = "world:{$this->name}:$X:$Z";
|
|
||||||
if(($cache = Cache::get($identifier)) !== false){
|
|
||||||
return $cache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$raw = [];
|
$raw = [];
|
||||||
for($Y = 0; $Y < 8; ++$Y){
|
for($Y = 0; $Y < 8; ++$Y){
|
||||||
|
|
@ -534,9 +517,6 @@ class Level{
|
||||||
$ordered .= substr($mini, $j << 5, 24); //16 + 8
|
$ordered .= substr($mini, $j << 5, 24); //16 + 8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(ADVANCED_CACHE == true and $Yndex == 0xff){
|
|
||||||
Cache::add($identifier, $ordered, 60);
|
|
||||||
}
|
|
||||||
return $ordered;
|
return $ordered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue