PocketMine-MP 5.44.4 git-6a7cc02e9dff59b69241aa0bcffdb9903ce86beb
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;
25use function count;
26
28 public const NETWORK_ID = ProtocolInfo::SERVERBOUND_DIAGNOSTICS_PACKET;
29
30 private float $avgFps;
31 private float $avgServerSimTickTimeMS;
32 private float $avgClientSimTickTimeMS;
33 private float $avgBeginFrameTimeMS;
34 private float $avgInputTimeMS;
35 private float $avgRenderTimeMS;
36 private float $avgEndFrameTimeMS;
37 private float $avgRemainderTimePercent;
38 private float $avgUnaccountedTimePercent;
43 private array $memoryCategoryValues = [];
48 private array $entityDiagnostics = [];
53 private array $systemDiagnostics = [];
58 private array $whiskerScopes = [];
59
71 public static function create(
72 float $avgFps,
73 float $avgServerSimTickTimeMS,
74 float $avgClientSimTickTimeMS,
75 float $avgBeginFrameTimeMS,
76 float $avgInputTimeMS,
77 float $avgRenderTimeMS,
78 float $avgEndFrameTimeMS,
79 float $avgRemainderTimePercent,
80 float $avgUnaccountedTimePercent,
81 array $memoryCategoryValues,
82 array $entityDiagnostics,
83 array $systemDiagnostics,
84 array $whiskerScopes,
85 ) : self{
86 $result = new self;
87 $result->avgFps = $avgFps;
88 $result->avgServerSimTickTimeMS = $avgServerSimTickTimeMS;
89 $result->avgClientSimTickTimeMS = $avgClientSimTickTimeMS;
90 $result->avgBeginFrameTimeMS = $avgBeginFrameTimeMS;
91 $result->avgInputTimeMS = $avgInputTimeMS;
92 $result->avgRenderTimeMS = $avgRenderTimeMS;
93 $result->avgEndFrameTimeMS = $avgEndFrameTimeMS;
94 $result->avgRemainderTimePercent = $avgRemainderTimePercent;
95 $result->avgUnaccountedTimePercent = $avgUnaccountedTimePercent;
96 $result->memoryCategoryValues = $memoryCategoryValues;
97 $result->entityDiagnostics = $entityDiagnostics;
98 $result->systemDiagnostics = $systemDiagnostics;
99 $result->whiskerScopes = $whiskerScopes;
100 return $result;
101 }
102
103 public function getAvgFps() : float{ return $this->avgFps; }
104
105 public function getAvgServerSimTickTimeMS() : float{ return $this->avgServerSimTickTimeMS; }
106
107 public function getAvgClientSimTickTimeMS() : float{ return $this->avgClientSimTickTimeMS; }
108
109 public function getAvgBeginFrameTimeMS() : float{ return $this->avgBeginFrameTimeMS; }
110
111 public function getAvgInputTimeMS() : float{ return $this->avgInputTimeMS; }
112
113 public function getAvgRenderTimeMS() : float{ return $this->avgRenderTimeMS; }
114
115 public function getAvgEndFrameTimeMS() : float{ return $this->avgEndFrameTimeMS; }
116
117 public function getAvgRemainderTimePercent() : float{ return $this->avgRemainderTimePercent; }
118
119 public function getAvgUnaccountedTimePercent() : float{ return $this->avgUnaccountedTimePercent; }
120
125 public function getMemoryCategoryValues() : array{ return $this->memoryCategoryValues; }
126
131 public function getEntityDiagnostics() : array{ return $this->entityDiagnostics; }
132
137 public function getSystemDiagnostics() : array{ return $this->systemDiagnostics; }
138
143 public function getWhiskerScopes() : array{ return $this->whiskerScopes; }
144
145 protected function decodePayload(ByteBufferReader $in) : void{
146 $this->avgFps = LE::readFloat($in);
147 $this->avgServerSimTickTimeMS = LE::readFloat($in);
148 $this->avgClientSimTickTimeMS = LE::readFloat($in);
149 $this->avgBeginFrameTimeMS = LE::readFloat($in);
150 $this->avgInputTimeMS = LE::readFloat($in);
151 $this->avgRenderTimeMS = LE::readFloat($in);
152 $this->avgEndFrameTimeMS = LE::readFloat($in);
153 $this->avgRemainderTimePercent = LE::readFloat($in);
154 $this->avgUnaccountedTimePercent = LE::readFloat($in);
155
156 $this->memoryCategoryValues = [];
157 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
158 $this->memoryCategoryValues[] = MemoryCategoryCounter::read($in);
159 }
160
161 $this->entityDiagnostics = [];
162 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
163 $this->entityDiagnostics[] = EntityDiagnosticTimingInfo::read($in);
164 }
165
166 $this->systemDiagnostics = [];
167 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
168 $this->systemDiagnostics[] = SystemDiagnosticTimingInfo::read($in);
169 }
170
171 $this->whiskerScopes = [];
172 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
173 $this->whiskerScopes[] = WhiskerScopeDataSummary::read($in);
174 }
175 }
176
177 protected function encodePayload(ByteBufferWriter $out) : void{
178 LE::writeFloat($out, $this->avgFps);
179 LE::writeFloat($out, $this->avgServerSimTickTimeMS);
180 LE::writeFloat($out, $this->avgClientSimTickTimeMS);
181 LE::writeFloat($out, $this->avgBeginFrameTimeMS);
182 LE::writeFloat($out, $this->avgInputTimeMS);
183 LE::writeFloat($out, $this->avgRenderTimeMS);
184 LE::writeFloat($out, $this->avgEndFrameTimeMS);
185 LE::writeFloat($out, $this->avgRemainderTimePercent);
186 LE::writeFloat($out, $this->avgUnaccountedTimePercent);
187
188 VarInt::writeUnsignedInt($out, count($this->memoryCategoryValues));
189 foreach($this->memoryCategoryValues as $value){
190 $value->write($out);
191 }
192
193 VarInt::writeUnsignedInt($out, count($this->entityDiagnostics));
194 foreach($this->entityDiagnostics as $value){
195 $value->write($out);
196 }
197
198 VarInt::writeUnsignedInt($out, count($this->systemDiagnostics));
199 foreach($this->systemDiagnostics as $value){
200 $value->write($out);
201 }
202
203 VarInt::writeUnsignedInt($out, count($this->whiskerScopes));
204 foreach($this->whiskerScopes as $value){
205 $value->write($out);
206 }
207 }
208
209 public function handle(PacketHandlerInterface $handler) : bool{
210 return $handler->handleServerboundDiagnostics($this);
211 }
212}
static create(float $avgFps, float $avgServerSimTickTimeMS, float $avgClientSimTickTimeMS, float $avgBeginFrameTimeMS, float $avgInputTimeMS, float $avgRenderTimeMS, float $avgEndFrameTimeMS, float $avgRemainderTimePercent, float $avgUnaccountedTimePercent, array $memoryCategoryValues, array $entityDiagnostics, array $systemDiagnostics, array $whiskerScopes,)