diff --git a/CHANGELOG.md b/CHANGELOG.md index 31019760..6d4a8c18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/client.rs b/src/client.rs index 6fa3fadd..7ba3e882 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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, diff --git a/src/client/diagnostics.rs b/src/client/diagnostics.rs index b35902ba..73df8e7b 100644 --- a/src/client/diagnostics.rs +++ b/src/client/diagnostics.rs @@ -107,6 +107,7 @@ impl ClientDiagnosticsPlugin { fn add_measurements( mut diagnostics: Diagnostics, stats: Res, + mut last_stats: Local, client: Res, ) { diagnostics.add_measurement(&Self::RTT, || client.rtt()); @@ -114,13 +115,24 @@ impl ClientDiagnosticsPlugin { 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; } }