From afb7c0683696b5a1a435d5f898a733856befd1b8 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Tue, 31 Oct 2023 21:05:18 +0200 Subject: [PATCH] Add tracing for replication messages --- CHANGELOG.md | 5 +++++ src/client.rs | 4 +++- src/server.rs | 2 ++ src/server/replication_buffer.rs | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6be0b99..e3d2db5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Tracing for replication messages. +- `Debug` derive for `LastRepliconTick`. + ## [0.16.0] - 2023-10-30 ### Added diff --git a/src/client.rs b/src/client.rs index 093aee05..587ec552 100644 --- a/src/client.rs +++ b/src/client.rs @@ -151,9 +151,11 @@ fn apply_tick( let mut last_tick = world.resource_mut::(); if last_tick.0 < tick { + trace!("applying {tick:?} over {last_tick:?}"); last_tick.0 = tick; Ok(Some(tick)) } else { + trace!("discarding {tick:?}, which is older then {last_tick:?}"); Ok(None) } } @@ -285,7 +287,7 @@ enum ComponentsKind { /// Last received tick from server. /// /// Used only on clients, sent to the server in last replicon ack message. -#[derive(Default, Resource, Deref)] +#[derive(Debug, Default, Deref, Resource)] pub struct LastRepliconTick(pub(super) RepliconTick); /// Set with replication and event systems related to client. diff --git a/src/server.rs b/src/server.rs index c1cb84e2..82180b66 100644 --- a/src/server.rs +++ b/src/server.rs @@ -110,6 +110,7 @@ impl ServerPlugin { /// Increments current server tick which causes the server to replicate this frame. pub fn increment_tick(mut tick: ResMut) { tick.increment(); + trace!("incremented {tick:?}"); } fn acks_receiving_system( @@ -125,6 +126,7 @@ impl ServerPlugin { if *acked_tick < tick { *acked_tick = tick; entity_map.cleanup_acked(client_id, *acked_tick); + trace!("client {client_id} acknowledged {tick:?}"); } } Err(e) => error!("unable to deserialize tick from client {client_id}: {e}"), diff --git a/src/server/replication_buffer.rs b/src/server/replication_buffer.rs index bd5335a5..6b29d6f0 100644 --- a/src/server/replication_buffer.rs +++ b/src/server/replication_buffer.rs @@ -298,11 +298,14 @@ impl ReplicationBuffer { if self.arrays_with_data > 0 || self.send_empty { self.trim_empty_arrays(); + trace!("sending replication message to client {}", self.client_id); server.send_message( self.client_id, replication_channel_id, Bytes::copy_from_slice(self.message.get_ref()), ); + } else { + trace!("nothing to send for client {}", self.client_id); } }