Skip to content

Commit

Permalink
Add tracing for replication messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Nov 1, 2023
1 parent 449333e commit afb7c06
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ fn apply_tick(

let mut last_tick = world.resource_mut::<LastRepliconTick>();
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)
}
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RepliconTick>) {
tick.increment();
trace!("incremented {tick:?}");
}

fn acks_receiving_system(
Expand All @@ -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}"),
Expand Down
3 changes: 3 additions & 0 deletions src/server/replication_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit afb7c06

Please sign in to comment.