Merge remote-tracking branch 'origin/stable' into minor-next

This commit is contained in:
Dylan K. Taylor
2023-03-31 21:28:14 +01:00
4 changed files with 20 additions and 4 deletions

View File

@@ -28,6 +28,7 @@ use pocketmine\entity\Entity;
use pocketmine\event\Event;
use pocketmine\network\mcpe\protocol\ClientboundPacket;
use pocketmine\network\mcpe\protocol\ServerboundPacket;
use pocketmine\player\Player;
use pocketmine\scheduler\TaskHandler;
use function get_class;
@@ -241,8 +242,14 @@ abstract class Timings{
}
public static function getEntityTimings(Entity $entity) : TimingsHandler{
$entityType = (new \ReflectionClass($entity))->getShortName();
$reflect = new \ReflectionClass($entity);
$entityType = $reflect->getShortName();
if(!isset(self::$entityTypeTimingMap[$entityType])){
//the timings viewer calculates average player count by looking at this timer, so we need to ensure it has
//a name it can identify. However, we also want to make it obvious if this is a custom Player class.
if($entity instanceof Player && $reflect->getName() !== Player::class){
$entityType = "Player (" . $reflect->getName() . ")";
}
self::$entityTypeTimingMap[$entityType] = new TimingsHandler(self::INCLUDED_BY_OTHER_TIMINGS_PREFIX . "Entity Tick - " . $entityType, self::$tickEntity);
}

View File

@@ -25,7 +25,7 @@ namespace pocketmine\timings;
use pocketmine\Server;
use pocketmine\utils\AssumptionFailedError;
use function round;
use function floor;
use function spl_object_id;
/**
@@ -60,7 +60,7 @@ final class TimingsRecord{
if($measure){
foreach(self::$records as $record){
if($record->curTickTotal > Server::TARGET_NANOSECONDS_PER_TICK){
$record->violations += (int) round($record->curTickTotal / Server::TARGET_NANOSECONDS_PER_TICK);
$record->violations += (int) floor($record->curTickTotal / Server::TARGET_NANOSECONDS_PER_TICK);
}
$record->curTickTotal = 0;
$record->curCount = 0;