PocketMine-MP 5.40.1 git-25718e8ccd903d1408fb25666ef84028379bbea6
Loading...
Searching...
No Matches
ServerboundDiagnosticsPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
22use function count;
23
25 public const NETWORK_ID = ProtocolInfo::SERVERBOUND_DIAGNOSTICS_PACKET;
26
27 private float $avgFps;
28 private float $avgServerSimTickTimeMS;
29 private float $avgClientSimTickTimeMS;
30 private float $avgBeginFrameTimeMS;
31 private float $avgInputTimeMS;
32 private float $avgRenderTimeMS;
33 private float $avgEndFrameTimeMS;
34 private float $avgRemainderTimePercent;
35 private float $avgUnaccountedTimePercent;
40 private array $memoryCategoryValues = [];
41
47 public static function create(
48 float $avgFps,
49 float $avgServerSimTickTimeMS,
50 float $avgClientSimTickTimeMS,
51 float $avgBeginFrameTimeMS,
52 float $avgInputTimeMS,
53 float $avgRenderTimeMS,
54 float $avgEndFrameTimeMS,
55 float $avgRemainderTimePercent,
56 float $avgUnaccountedTimePercent,
57 array $memoryCategoryValues,
58 ) : self{
59 $result = new self;
60 $result->avgFps = $avgFps;
61 $result->avgServerSimTickTimeMS = $avgServerSimTickTimeMS;
62 $result->avgClientSimTickTimeMS = $avgClientSimTickTimeMS;
63 $result->avgBeginFrameTimeMS = $avgBeginFrameTimeMS;
64 $result->avgInputTimeMS = $avgInputTimeMS;
65 $result->avgRenderTimeMS = $avgRenderTimeMS;
66 $result->avgEndFrameTimeMS = $avgEndFrameTimeMS;
67 $result->avgRemainderTimePercent = $avgRemainderTimePercent;
68 $result->avgUnaccountedTimePercent = $avgUnaccountedTimePercent;
69 $result->memoryCategoryValues = $memoryCategoryValues;
70 return $result;
71 }
72
73 public function getAvgFps() : float{ return $this->avgFps; }
74
75 public function getAvgServerSimTickTimeMS() : float{ return $this->avgServerSimTickTimeMS; }
76
77 public function getAvgClientSimTickTimeMS() : float{ return $this->avgClientSimTickTimeMS; }
78
79 public function getAvgBeginFrameTimeMS() : float{ return $this->avgBeginFrameTimeMS; }
80
81 public function getAvgInputTimeMS() : float{ return $this->avgInputTimeMS; }
82
83 public function getAvgRenderTimeMS() : float{ return $this->avgRenderTimeMS; }
84
85 public function getAvgEndFrameTimeMS() : float{ return $this->avgEndFrameTimeMS; }
86
87 public function getAvgRemainderTimePercent() : float{ return $this->avgRemainderTimePercent; }
88
89 public function getAvgUnaccountedTimePercent() : float{ return $this->avgUnaccountedTimePercent; }
90
95 public function getMemoryCategoryValues() : array{ return $this->memoryCategoryValues; }
96
97 protected function decodePayload(ByteBufferReader $in) : void{
98 $this->avgFps = LE::readFloat($in);
99 $this->avgServerSimTickTimeMS = LE::readFloat($in);
100 $this->avgClientSimTickTimeMS = LE::readFloat($in);
101 $this->avgBeginFrameTimeMS = LE::readFloat($in);
102 $this->avgInputTimeMS = LE::readFloat($in);
103 $this->avgRenderTimeMS = LE::readFloat($in);
104 $this->avgEndFrameTimeMS = LE::readFloat($in);
105 $this->avgRemainderTimePercent = LE::readFloat($in);
106 $this->avgUnaccountedTimePercent = LE::readFloat($in);
107
108 $this->memoryCategoryValues = [];
109 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
110 $this->memoryCategoryValues[] = MemoryCategoryCounter::read($in);
111 }
112 }
113
114 protected function encodePayload(ByteBufferWriter $out) : void{
115 LE::writeFloat($out, $this->avgFps);
116 LE::writeFloat($out, $this->avgServerSimTickTimeMS);
117 LE::writeFloat($out, $this->avgClientSimTickTimeMS);
118 LE::writeFloat($out, $this->avgBeginFrameTimeMS);
119 LE::writeFloat($out, $this->avgInputTimeMS);
120 LE::writeFloat($out, $this->avgRenderTimeMS);
121 LE::writeFloat($out, $this->avgEndFrameTimeMS);
122 LE::writeFloat($out, $this->avgRemainderTimePercent);
123 LE::writeFloat($out, $this->avgUnaccountedTimePercent);
124
125 VarInt::writeUnsignedInt($out, count($this->memoryCategoryValues));
126 foreach($this->memoryCategoryValues as $value){
127 $value->write($out);
128 }
129 }
130
131 public function handle(PacketHandlerInterface $handler) : bool{
132 return $handler->handleServerboundDiagnostics($this);
133 }
134}
static create(float $avgFps, float $avgServerSimTickTimeMS, float $avgClientSimTickTimeMS, float $avgBeginFrameTimeMS, float $avgInputTimeMS, float $avgRenderTimeMS, float $avgEndFrameTimeMS, float $avgRemainderTimePercent, float $avgUnaccountedTimePercent, array $memoryCategoryValues,)