/**
* Tries to execute a server tick
*/
private function tick()
{
$tickTime = microtime(true);
if ($tickTime < $this->nextTick) {
return false;
}
Timings::$serverTickTimer->startTiming();
++$this->tickCounter;
$this->checkConsole();
Timings::$connectionTimer->startTiming();
$this->network->processInterfaces();
Timings::$connectionTimer->stopTiming();
Timings::$schedulerTimer->startTiming();
$this->scheduler->mainThreadHeartbeat($this->tickCounter);
Timings::$schedulerTimer->stopTiming();
$this->checkTickUpdates($this->tickCounter);
if (($this->tickCounter & 0b1111) === 0) {
$this->titleTick();
if ($this->queryHandler !== null and ($this->tickCounter & 0b111111111) === 0) {
try {
$this->queryHandler->regenerateInfo();
} catch (\Exception $e) {
if ($this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
}
}
}
Timings::$generationTimer->startTiming();
try {
$this->generationManager->process();
} catch (\Exception $e) {
if ($this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
}
Timings::$generationTimer->stopTiming();
if ($this->tickCounter % 100 === 0) {
foreach ($this->levels as $level) {
$level->clearCache();
}
}
Timings::$serverTickTimer->stopTiming();
TimingsHandler::tick();
$now = microtime(true);
array_shift($this->tickAverage);
$this->tickAverage[] = min(20, 1 / max(0.001, $now - $tickTime));
array_shift($this->useAverage);
$this->useAverage[] = min(1, ($now - $tickTime) / 0.05);
if ($this->nextTick - $tickTime < -1) {
$this->nextTick = $tickTime;
}
$this->nextTick += 0.05;
return true;
}