PocketMine-MP 5.43.2 git-a137a986d01d9af23452b2e741699a770c7ae112
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;
24use function count;
25
27 public const NETWORK_ID = ProtocolInfo::SERVERBOUND_DIAGNOSTICS_PACKET;
28
29 private float $avgFps;
30 private float $avgServerSimTickTimeMS;
31 private float $avgClientSimTickTimeMS;
32 private float $avgBeginFrameTimeMS;
33 private float $avgInputTimeMS;
34 private float $avgRenderTimeMS;
35 private float $avgEndFrameTimeMS;
36 private float $avgRemainderTimePercent;
37 private float $avgUnaccountedTimePercent;
42 private array $memoryCategoryValues = [];
47 private array $entityDiagnostics = [];
52 private array $systemDiagnostics = [];
53
63 public static function create(
64 float $avgFps,
65 float $avgServerSimTickTimeMS,
66 float $avgClientSimTickTimeMS,
67 float $avgBeginFrameTimeMS,
68 float $avgInputTimeMS,
69 float $avgRenderTimeMS,
70 float $avgEndFrameTimeMS,
71 float $avgRemainderTimePercent,
72 float $avgUnaccountedTimePercent,
73 array $memoryCategoryValues,
74 array $entityDiagnostics,
75 array $systemDiagnostics,
76 ) : self{
77 $result = new self;
78 $result->avgFps = $avgFps;
79 $result->avgServerSimTickTimeMS = $avgServerSimTickTimeMS;
80 $result->avgClientSimTickTimeMS = $avgClientSimTickTimeMS;
81 $result->avgBeginFrameTimeMS = $avgBeginFrameTimeMS;
82 $result->avgInputTimeMS = $avgInputTimeMS;
83 $result->avgRenderTimeMS = $avgRenderTimeMS;
84 $result->avgEndFrameTimeMS = $avgEndFrameTimeMS;
85 $result->avgRemainderTimePercent = $avgRemainderTimePercent;
86 $result->avgUnaccountedTimePercent = $avgUnaccountedTimePercent;
87 $result->memoryCategoryValues = $memoryCategoryValues;
88 $result->entityDiagnostics = $entityDiagnostics;
89 $result->systemDiagnostics = $systemDiagnostics;
90 return $result;
91 }
92
93 public function getAvgFps() : float{ return $this->avgFps; }
94
95 public function getAvgServerSimTickTimeMS() : float{ return $this->avgServerSimTickTimeMS; }
96
97 public function getAvgClientSimTickTimeMS() : float{ return $this->avgClientSimTickTimeMS; }
98
99 public function getAvgBeginFrameTimeMS() : float{ return $this->avgBeginFrameTimeMS; }
100
101 public function getAvgInputTimeMS() : float{ return $this->avgInputTimeMS; }
102
103 public function getAvgRenderTimeMS() : float{ return $this->avgRenderTimeMS; }
104
105 public function getAvgEndFrameTimeMS() : float{ return $this->avgEndFrameTimeMS; }
106
107 public function getAvgRemainderTimePercent() : float{ return $this->avgRemainderTimePercent; }
108
109 public function getAvgUnaccountedTimePercent() : float{ return $this->avgUnaccountedTimePercent; }
110
115 public function getMemoryCategoryValues() : array{ return $this->memoryCategoryValues; }
116
121 public function getEntityDiagnostics() : array{ return $this->entityDiagnostics; }
122
127 public function getSystemDiagnostics() : array{ return $this->systemDiagnostics; }
128
129 protected function decodePayload(ByteBufferReader $in) : void{
130 $this->avgFps = LE::readFloat($in);
131 $this->avgServerSimTickTimeMS = LE::readFloat($in);
132 $this->avgClientSimTickTimeMS = LE::readFloat($in);
133 $this->avgBeginFrameTimeMS = LE::readFloat($in);
134 $this->avgInputTimeMS = LE::readFloat($in);
135 $this->avgRenderTimeMS = LE::readFloat($in);
136 $this->avgEndFrameTimeMS = LE::readFloat($in);
137 $this->avgRemainderTimePercent = LE::readFloat($in);
138 $this->avgUnaccountedTimePercent = LE::readFloat($in);
139
140 $this->memoryCategoryValues = [];
141 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
142 $this->memoryCategoryValues[] = MemoryCategoryCounter::read($in);
143 }
144
145 $this->entityDiagnostics = [];
146 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
147 $this->entityDiagnostics[] = EntityDiagnosticTimingInfo::read($in);
148 }
149
150 $this->systemDiagnostics = [];
151 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
152 $this->systemDiagnostics[] = SystemDiagnosticTimingInfo::read($in);
153 }
154 }
155
156 protected function encodePayload(ByteBufferWriter $out) : void{
157 LE::writeFloat($out, $this->avgFps);
158 LE::writeFloat($out, $this->avgServerSimTickTimeMS);
159 LE::writeFloat($out, $this->avgClientSimTickTimeMS);
160 LE::writeFloat($out, $this->avgBeginFrameTimeMS);
161 LE::writeFloat($out, $this->avgInputTimeMS);
162 LE::writeFloat($out, $this->avgRenderTimeMS);
163 LE::writeFloat($out, $this->avgEndFrameTimeMS);
164 LE::writeFloat($out, $this->avgRemainderTimePercent);
165 LE::writeFloat($out, $this->avgUnaccountedTimePercent);
166
167 VarInt::writeUnsignedInt($out, count($this->memoryCategoryValues));
168 foreach($this->memoryCategoryValues as $value){
169 $value->write($out);
170 }
171
172 VarInt::writeUnsignedInt($out, count($this->entityDiagnostics));
173 foreach($this->entityDiagnostics as $value){
174 $value->write($out);
175 }
176
177 VarInt::writeUnsignedInt($out, count($this->systemDiagnostics));
178 foreach($this->systemDiagnostics as $value){
179 $value->write($out);
180 }
181 }
182
183 public function handle(PacketHandlerInterface $handler) : bool{
184 return $handler->handleServerboundDiagnostics($this);
185 }
186}
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,)