-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(world): added PlayerDiagnostics
- Loading branch information
Showing
5 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
DisconnectReason, | ||
ServerboundDiagnosticsPacket | ||
} from "@serenityjs/protocol"; | ||
|
||
import { SerenityHandler } from "./serenity-handler"; | ||
|
||
import type { NetworkSession } from "@serenityjs/network"; | ||
|
||
class ServerboundDiagnostics extends SerenityHandler { | ||
public static readonly packet = ServerboundDiagnosticsPacket.id; | ||
|
||
public static handle( | ||
packet: ServerboundDiagnosticsPacket, | ||
session: NetworkSession | ||
): void { | ||
// Get the player from the session | ||
// If there is no player, then disconnect the session. | ||
const player = this.serenity.getPlayer(session); | ||
if (!player) | ||
return session.disconnect( | ||
"Failed to connect due to an invalid player. Please try again.", | ||
DisconnectReason.InvalidPlayer | ||
); | ||
|
||
// Get the diagnostics from the player | ||
const diagnostics = player.diagnostics; | ||
|
||
// Set the diagnostics enabled property to true | ||
if (!diagnostics.enabled) diagnostics.enabled = true; | ||
|
||
// Set the diagnostics properties | ||
diagnostics.fps = packet.fps; | ||
diagnostics.serverSimTickTime = packet.serverSimTickTime; | ||
diagnostics.clientSimTickTime = packet.clientSimTickTime; | ||
diagnostics.beginFrameTime = packet.beginFrameTime; | ||
diagnostics.inputTime = packet.inputTime; | ||
diagnostics.renderTime = packet.renderTime; | ||
diagnostics.endFrameTime = packet.endFrameTime; | ||
diagnostics.remainderTimePercent = packet.remainderTimePercent; | ||
diagnostics.unaccountedTimePercent = packet.unaccountedTimePercent; | ||
} | ||
} | ||
|
||
export { ServerboundDiagnostics }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class PlayerDiagnostic { | ||
/** | ||
* Whether the diagnostic is enabled client-side. | ||
*/ | ||
public enabled = false; | ||
|
||
/** | ||
* The client's frames per second. | ||
*/ | ||
public fps = 0; | ||
|
||
/** | ||
* The server simulation tick time. | ||
*/ | ||
public serverSimTickTime = 0; | ||
|
||
/** | ||
* The client simulation tick time. | ||
*/ | ||
public clientSimTickTime = 0; | ||
|
||
/** | ||
* The time the frame began. | ||
*/ | ||
public beginFrameTime = 0; | ||
|
||
/** | ||
* The time the input was received. | ||
*/ | ||
public inputTime = 0; | ||
|
||
/** | ||
* The time the frame was rendered | ||
*/ | ||
public renderTime = 0; | ||
|
||
/** | ||
* The time the frame ended. | ||
*/ | ||
public endFrameTime = 0; | ||
|
||
/** | ||
* The remainder time percentage. | ||
*/ | ||
public remainderTimePercent = 0; | ||
|
||
/** | ||
* The percentage of time that was unaccounted for in the frame. | ||
*/ | ||
public unaccountedTimePercent = 0; | ||
} | ||
|
||
export { PlayerDiagnostic }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters