Skip to content

Commit

Permalink
Fix client diagnostics (#377)
Browse files Browse the repository at this point in the history
Bevy diagnostics (measurements) should only record the change in
the value since lass time the measurements were collected.
_Not_ the life-time total.
  • Loading branch information
matoous authored Dec 16, 2024
1 parent 6b9bd43 commit 3692955
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Report bevy diagnostics correctly as a delta since last measurement collection.

## [0.29.0] - 2024-12-02

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ pub(super) struct BufferedMutate {
///
/// See also [`ClientDiagnosticsPlugin`](diagnostics::ClientDiagnosticsPlugin)
/// for automatic integration with Bevy diagnostics.
#[derive(Default, Resource, Debug)]
#[derive(Clone, Copy, Default, Resource, Debug)]
pub struct ClientReplicationStats {
/// Incremented per entity that changes.
pub entities_changed: usize,
Expand Down
24 changes: 18 additions & 6 deletions src/client/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,32 @@ impl ClientDiagnosticsPlugin {
fn add_measurements(
mut diagnostics: Diagnostics,
stats: Res<ClientReplicationStats>,
mut last_stats: Local<ClientReplicationStats>,
client: Res<RepliconClient>,
) {
diagnostics.add_measurement(&Self::RTT, || client.rtt());
diagnostics.add_measurement(&Self::PACKET_LOSS, || client.packet_loss());
diagnostics.add_measurement(&Self::SENT_BPS, || client.sent_bps());
diagnostics.add_measurement(&Self::RECEIVED_BPS, || client.received_bps());

diagnostics.add_measurement(&Self::ENTITIES_CHANGED, || stats.entities_changed as f64);
diagnostics.add_measurement(&Self::ENTITIES_CHANGED, || {
(stats.entities_changed - last_stats.entities_changed) as f64
});
diagnostics.add_measurement(&Self::COMPONENTS_CHANGED, || {
stats.components_changed as f64
(stats.components_changed - last_stats.components_changed) as f64
});
diagnostics.add_measurement(&Self::MAPPINGS, || {
(stats.mappings - last_stats.mappings) as f64
});
diagnostics.add_measurement(&Self::DESPAWNS, || {
(stats.despawns - last_stats.despawns) as f64
});
diagnostics.add_measurement(&Self::REPLICATION_MESSAGES, || {
(stats.messages - last_stats.messages) as f64
});
diagnostics.add_measurement(&Self::REPLICATION_BYTES, || {
(stats.bytes - last_stats.bytes) as f64
});
diagnostics.add_measurement(&Self::MAPPINGS, || stats.mappings as f64);
diagnostics.add_measurement(&Self::DESPAWNS, || stats.despawns as f64);
diagnostics.add_measurement(&Self::REPLICATION_MESSAGES, || stats.messages as f64);
diagnostics.add_measurement(&Self::REPLICATION_BYTES, || stats.bytes as f64);
*last_stats = *stats;
}
}

0 comments on commit 3692955

Please sign in to comment.