Skip to content

Commit

Permalink
review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB committed Jan 10, 2024
1 parent 10e3c56 commit 63d98bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use bevy_renet::{renet::RenetClient, transport::NetcodeClientPlugin, RenetClient
use bincode::{DefaultOptions, Options};
use varint_rs::VarintReader;

use crate::has_authority;
use crate::replicon_core::{
replication_rules::{Replication, ReplicationRules},
replicon_tick::RepliconTick,
Expand All @@ -31,7 +30,6 @@ impl Plugin for ClientPlugin {
ClientSet::ResetEvents
.after(NetcodeClientPlugin::update_system)
.before(ClientSet::Receive)
.run_if(not(has_authority()))
.run_if(client_just_connected()),
)
.configure_sets(
Expand Down Expand Up @@ -491,10 +489,18 @@ pub enum ClientSet {
///
/// If this set is disabled, then you need to manually clean up the client after a disconnect or when
/// reconnecting.
/// You may want to disable this set if you want to preserve client replication state across reconnects.
/// In that case, you need to manually repair the client state (or use something like
/// [bevy_replicon_repair](https://github.com/UkoeHB/bevy_replicon_repair)).
Reset,
/// Systems that reset queued server events.
///
/// Runs in `PreUpdate` immediately after the client connects to ensure client sessions have a fresh start.
///
/// This is a separate set from `ClientSet::Reset` because the reset requirements for events are different
/// from the replicon client internals.
/// It is best practice to discard client-sent and server-received events while the client is not connected
/// in order to guarantee clean separation between connection sessions.
ResetEvents,
}

Expand Down
19 changes: 6 additions & 13 deletions src/network_event/server_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,13 @@ fn local_resending_system<T: Event>(
///
/// We clear events while waiting for a connection to ensure clean reconnects.
fn reset_system<T: Event>(mut event_queue: ResMut<ServerEventQueue<T>>) {
if !event_queue.is_empty() {
warn!("discarding {} queued server events due to a disconnect", event_queue.len());
if !event_queue.0.is_empty() {
warn!(
"discarding {} queued server events due to a disconnect",
event_queue.0.values_len()
);
}
event_queue.clear();
event_queue.0.clear();
}

/// Sends serialized `message` to clients.
Expand Down Expand Up @@ -352,16 +355,6 @@ pub enum SendMode {
pub struct ServerEventQueue<T>(ListOrderedMultimap<RepliconTick, T>);

impl<T> ServerEventQueue<T> {
/// Gets the event queue length.
pub fn len(&mut self) -> usize {
self.0.values_len()
}

/// Tests whether there are any events queued.
pub fn is_empty(&mut self) -> bool {
self.len() == 0
}

/// Clears the event queue.
pub fn clear(&mut self) {
self.0.clear();
Expand Down

0 comments on commit 63d98bb

Please sign in to comment.