diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ea10cbf..673aa80c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,10 +30,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Provide replication statistics by sum instead of per second and use `usize` for it. - Use fixed integer encoding for ticks for server events. - Rename `ServerPlugin::change_timeout` into `ServerPlugin::mutations_timeout`. -- Rename `ServerInitTick` into `ServerChangeTick`. +- Rename `ServerInitTick` into `ServerUpdateTick`. - Rename `ReplicatedClient::init_tick` into `ReplicatedClient::change_tick`. - Rename `ReplicatedClient::get_change_tick` into `ReplicatedClient::mutation_tick`. -- Rename `ReplicationChannel::Init` into `ReplicationChannel::Changes`. +- Rename `ReplicationChannel::Init` into `ReplicationChannel::Updates`. - Rename `ReplicationChannel::Update` into `ReplicationChannel::Mutations`. - Rename `ClientStats` into `ClientReplicationStats`. - Rename `ClientDiagnosticsPlugin::MESSAGES` into `ClientDiagnosticsPlugin::REPLICATION_MESSAGES`. diff --git a/src/client.rs b/src/client.rs index 47956be1..5bad6a4a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -15,7 +15,6 @@ use crate::core::{ channels::{ReplicationChannel, RepliconChannels}, common_conditions::{client_connected, client_just_connected, client_just_disconnected}, replication::{ - change_message_flags::ChangeMessageFlags, command_markers::{CommandMarkers, EntityMarkers}, deferred_entity::DeferredEntity, replication_registry::{ @@ -23,6 +22,7 @@ use crate::core::{ ReplicationRegistry, }, track_mutate_messages::TrackMutateMessages, + update_message_flags::UpdateMessageFlags, Replicated, }, replicon_client::RepliconClient, @@ -41,7 +41,7 @@ impl Plugin for ClientPlugin { fn build(&self, app: &mut App) { app.init_resource::() .init_resource::() - .init_resource::() + .init_resource::() .init_resource::() .add_event::() .add_event::() @@ -87,12 +87,12 @@ impl ClientPlugin { /// Receives and applies replication messages from the server. /// - /// Change messages are sent over the [`ReplicationChannel::Changes`] and are applied first to ensure valid state + /// Update messages are sent over the [`ReplicationChannel::Updates`] and are applied first to ensure valid state /// for component mutations. /// /// Mutate messages are sent over [`ReplicationChannel::Mutations`], which means they may appear - /// ahead-of or behind change messages from the same server tick. A mutation will only be applied if its - /// change tick has already appeared in an change message, otherwise it will be buffered while waiting. + /// ahead-of or behind update messages from the same server tick. A mutation will only be applied if its + /// update tick has already appeared in an update message, otherwise it will be buffered while waiting. /// Since component mutations can arrive in any order, they will only be applied if they correspond to a more /// recent server tick than the last acked server tick for each entity. /// @@ -153,12 +153,12 @@ impl ClientPlugin { } fn reset( - mut change_tick: ResMut, + mut update_tick: ResMut, mut entity_map: ResMut, mut buffered_mutations: ResMut, stats: Option>, ) { - *change_tick = Default::default(); + *update_tick = Default::default(); entity_map.clear(); buffered_mutations.clear(); if let Some(mut stats) = stats { @@ -176,16 +176,16 @@ fn apply_replication( client: &mut RepliconClient, buffered_mutations: &mut BufferedMutations, ) -> bincode::Result<()> { - for message in client.receive(ReplicationChannel::Changes) { - apply_change_message(world, params, &message)?; + for message in client.receive(ReplicationChannel::Updates) { + apply_update_message(world, params, &message)?; } - // Unlike change messages, we read all mutate messages first, sort them by tick + // Unlike update messages, we read all mutate messages first, sort them by tick // in descending order to ensure that the last mutation will be applied first. // Since mutate messages manually split by packet size, we apply all messages, // but skip outdated data per-entity by checking last received tick for it // (unless user requested history via marker). - let change_tick = *world.resource::(); + let update_tick = *world.resource::(); let acks_size = mem::size_of::() * client.received_count(ReplicationChannel::Mutations); if acks_size != 0 { let mut acks = Vec::with_capacity(acks_size); @@ -193,16 +193,16 @@ fn apply_replication( let mutate_index = buffer_mutate_message(params, buffered_mutations, message)?; bincode::serialize_into(&mut acks, &mutate_index)?; } - client.send(ReplicationChannel::Changes, acks); + client.send(ReplicationChannel::Updates, acks); } - apply_mutate_messages(world, params, buffered_mutations, change_tick) + apply_mutate_messages(world, params, buffered_mutations, update_tick) } -/// Reads and applies a change message. +/// Reads and applies an update message. /// /// For details see [`replication_messages`](crate::server::replication_messages). -fn apply_change_message( +fn apply_update_message( world: &mut World, params: &mut ReceiveParams, message: &[u8], @@ -214,12 +214,12 @@ fn apply_change_message( stats.bytes += end_pos; } - let flags = ChangeMessageFlags::from_bits_retain(cursor.read_fixedint()?); + let flags = UpdateMessageFlags::from_bits_retain(cursor.read_fixedint()?); debug_assert!(!flags.is_empty(), "message can't be empty"); let message_tick = bincode::deserialize_from(&mut cursor)?; - trace!("applying change message for {message_tick:?}"); - world.resource_mut::().0 = message_tick; + trace!("applying update message for {message_tick:?}"); + world.resource_mut::().0 = message_tick; let last_flag = flags.last(); for (_, flag) in flags.iter_names() { @@ -230,7 +230,7 @@ fn apply_change_message( }; match flag { - ChangeMessageFlags::MAPPINGS => { + UpdateMessageFlags::MAPPINGS => { debug_assert_eq!(array_kind, ArrayKind::Sized); let len = apply_array(array_kind, &mut cursor, |cursor| { apply_entity_mapping(world, params, cursor) @@ -239,7 +239,7 @@ fn apply_change_message( stats.mappings += len; } } - ChangeMessageFlags::DESPAWNS => { + UpdateMessageFlags::DESPAWNS => { let len = apply_array(array_kind, &mut cursor, |cursor| { apply_despawn(world, params, cursor, message_tick) })?; @@ -247,7 +247,7 @@ fn apply_change_message( stats.despawns += len; } } - ChangeMessageFlags::REMOVALS => { + UpdateMessageFlags::REMOVALS => { let len = apply_array(array_kind, &mut cursor, |cursor| { apply_removals(world, params, cursor, message_tick) })?; @@ -255,7 +255,7 @@ fn apply_change_message( stats.entities_changed += len; } } - ChangeMessageFlags::CHANGES => { + UpdateMessageFlags::CHANGES => { debug_assert_eq!(array_kind, ArrayKind::Dynamic); let len = apply_array(array_kind, &mut cursor, |cursor| { apply_changes(world, params, cursor, message_tick) @@ -288,7 +288,7 @@ fn buffer_mutate_message( stats.bytes += end_pos; } - let change_tick = bincode::deserialize_from(&mut cursor)?; + let update_tick = bincode::deserialize_from(&mut cursor)?; let message_tick = bincode::deserialize_from(&mut cursor)?; let messages_count = if params.mutate_ticks.is_some() { cursor.read_varint()? @@ -298,7 +298,7 @@ fn buffer_mutate_message( let mutate_index = cursor.read_varint()?; trace!("received mutate message for {message_tick:?}"); buffered_mutations.insert(BufferedMutate { - change_tick, + update_tick, message_tick, messages_count, message: message.slice(cursor.position() as usize..), @@ -309,17 +309,17 @@ fn buffer_mutate_message( /// Applies mutations from [`BufferedMutations`]. /// -/// If the mutate message can't be applied yet (because the change message with the +/// If the mutate message can't be applied yet (because the update message with the /// corresponding tick hasn't arrived), it will be kept in the buffer. fn apply_mutate_messages( world: &mut World, params: &mut ReceiveParams, buffered_mutations: &mut BufferedMutations, - change_tick: ServerChangeTick, + update_tick: ServerUpdateTick, ) -> bincode::Result<()> { let mut result = Ok(()); buffered_mutations.0.retain(|mutate| { - if mutate.change_tick > *change_tick { + if mutate.update_tick > *update_tick { return true; } @@ -374,7 +374,7 @@ fn apply_entity_mapping( Ok(()) } -/// Deserializes and applies entity despawn from change message. +/// Deserializes and applies entity despawn from update message. fn apply_despawn( world: &mut World, params: &mut ReceiveParams, @@ -567,7 +567,7 @@ fn apply_mutations( let data_size: usize = cursor.read_varint()?; let Some(client_entity) = params.entity_map.get_by_server(server_entity) else { - // Mutation could arrive after a despawn from change message. + // Mutation could arrive after a despawn from update message. debug!("ignoring mutations received for unknown server's {server_entity:?}"); cursor.set_position(cursor.position() + data_size as u64); return Ok(()); @@ -746,16 +746,16 @@ pub enum ClientSet { Reset, } -/// Last received tick for change messages from the server. +/// Last received tick for update messages from the server. /// /// In other words, the last [`RepliconTick`] with a removal, insertion, spawn or despawn. /// This value is not updated when mutation messages are received from the server. /// /// See also [`ServerMutateTicks`]. #[derive(Clone, Copy, Debug, Default, Deref, Resource)] -pub struct ServerChangeTick(RepliconTick); +pub struct ServerUpdateTick(RepliconTick); -/// Cached buffered mutate messages, used to synchronize mutations with change messages. +/// Cached buffered mutate messages, used to synchronize mutations with update messages. /// /// If [`ClientSet::Reset`] is disabled, then this needs to be cleaned up manually with [`Self::clear`]. #[derive(Default, Resource)] @@ -775,12 +775,12 @@ impl BufferedMutations { } } -/// Partially-deserialized mutate message that is waiting for its tick to appear in an change message. +/// Partially-deserialized mutate message that is waiting for its tick to appear in an update message. /// /// See also [`crate::server::replication_messages`]. pub(super) struct BufferedMutate { /// Required tick to wait for. - change_tick: RepliconTick, + update_tick: RepliconTick, /// The tick this mutations corresponds to. message_tick: RepliconTick, diff --git a/src/client/confirm_history.rs b/src/client/confirm_history.rs index 89fe7b50..cd0a45e7 100644 --- a/src/client/confirm_history.rs +++ b/src/client/confirm_history.rs @@ -126,12 +126,12 @@ impl ConfirmHistory { } } -/// Triggered for an entity when it receives changes for a tick. +/// Triggered for an entity when it receives updates for a tick. /// /// See also [`ConfirmHistory`]. #[derive(Debug, Event, Clone, Copy)] pub struct EntityReplicated { - /// Entity that received changes. + /// Entity that received an update. pub entity: Entity, /// Message tick. diff --git a/src/client/events.rs b/src/client/events.rs index ca98fcfc..f02b4648 100644 --- a/src/client/events.rs +++ b/src/client/events.rs @@ -1,4 +1,4 @@ -use super::{ClientPlugin, ClientSet, ServerChangeTick}; +use super::{ClientPlugin, ClientSet, ServerUpdateTick}; use crate::core::{ common_conditions::*, event_registry::{ @@ -85,7 +85,7 @@ impl ClientEventsPlugin { world.resource_scope(|world, registry: Mut| { world.resource_scope(|world, entity_map: Mut| { world.resource_scope(|world, event_registry: Mut| { - let change_tick = **world.resource::(); + let update_tick = **world.resource::(); let mut ctx = ClientReceiveCtx { registry: ®istry.read(), entity_map: &entity_map, @@ -112,7 +112,7 @@ impl ClientEventsPlugin { events.into_inner(), queue.into_inner(), &mut client, - change_tick, + update_tick, ) }; } diff --git a/src/client/server_mutate_ticks.rs b/src/client/server_mutate_ticks.rs index 035e33d7..dea88868 100644 --- a/src/client/server_mutate_ticks.rs +++ b/src/client/server_mutate_ticks.rs @@ -14,7 +14,7 @@ use crate::core::replicon_tick::RepliconTick; /// [`TrackAppExt::track_mutate_messages`](crate::core::replication::track_mutate_messages::TrackAppExt::track_mutate_messages) /// were called. /// -/// See also [`MutateTickReceived`] and [`ServerChangeTick`](super::ServerChangeTick). +/// See also [`MutateTickReceived`] and [`ServerUpdateTick`](super::ServerUpdateTick). #[derive(Debug, Resource)] pub struct ServerMutateTicks { ticks: VecDeque, diff --git a/src/core/channels.rs b/src/core/channels.rs index 7a93d72a..1833cf1e 100644 --- a/src/core/channels.rs +++ b/src/core/channels.rs @@ -10,7 +10,7 @@ pub enum ReplicationChannel { /// For sending messages with entity mappings, inserts, removals and despawns. /// /// This is an ordered reliable channel. - Changes, + Updates, /// For sending messages with component mutations. /// /// This is an unreliable channel. @@ -20,7 +20,7 @@ pub enum ReplicationChannel { impl From for RepliconChannel { fn from(value: ReplicationChannel) -> Self { match value { - ReplicationChannel::Changes => ChannelKind::Ordered.into(), + ReplicationChannel::Updates => ChannelKind::Ordered.into(), ReplicationChannel::Mutations => ChannelKind::Unreliable.into(), } } @@ -53,11 +53,11 @@ impl Default for RepliconChannels { fn default() -> Self { Self { server: vec![ - ReplicationChannel::Changes.into(), + ReplicationChannel::Updates.into(), ReplicationChannel::Mutations.into(), ], client: vec![ - ReplicationChannel::Changes.into(), + ReplicationChannel::Updates.into(), ReplicationChannel::Mutations.into(), ], default_max_bytes: 5 * 1024 * 1024, diff --git a/src/core/event_registry/server_event.rs b/src/core/event_registry/server_event.rs index 5686c246..eb1a7868 100644 --- a/src/core/event_registry/server_event.rs +++ b/src/core/event_registry/server_event.rs @@ -133,7 +133,7 @@ pub trait ServerEventAppExt { /// /// By default, all server events are buffered on server until server tick /// and queued on client until all insertions, removals and despawns - /// (value changes doesn't count) are replicated for the tick on which the + /// (value mutations doesn't count) are replicated for the tick on which the /// event was triggered. This is necessary to ensure that the executed logic /// during the event does not affect components or entities that the client /// has not yet received. @@ -340,9 +340,9 @@ impl ServerEvent { events: PtrMut, queue: PtrMut, client: &mut RepliconClient, - change_tick: RepliconTick, + update_tick: RepliconTick, ) { - (self.receive)(self, ctx, events, queue, client, change_tick); + (self.receive)(self, ctx, events, queue, client, update_tick); } /// Drains events [`ToClients`] and re-emits them as `E` if the server is in the list of the event recipients. @@ -494,12 +494,12 @@ unsafe fn receive( events: PtrMut, queue: PtrMut, client: &mut RepliconClient, - change_tick: RepliconTick, + update_tick: RepliconTick, ) { let events: &mut Events = events.deref_mut(); let queue: &mut ServerEventQueue = queue.deref_mut(); - while let Some((tick, message)) = queue.pop_if_le(change_tick) { + while let Some((tick, message)) = queue.pop_if_le(update_tick) { let mut cursor = Cursor::new(&*message); match event_data.deserialize(ctx, &mut cursor) { Ok(event) => { @@ -529,7 +529,7 @@ unsafe fn receive( continue; } }; - if tick > change_tick { + if tick > update_tick { trace!("queuing event `{}` with `{tick:?}`", any::type_name::()); queue.insert(tick, message.slice(cursor.position() as usize..)); continue; @@ -660,7 +660,7 @@ unsafe fn send_independent_event( /// Helper for serializing a server event. /// -/// Will prepend padding bytes for where the change tick will be inserted to the injected message. +/// Will prepend padding bytes for where the update tick will be inserted to the injected message. /// /// # Safety /// @@ -695,32 +695,32 @@ enum SerializedMessage { } impl SerializedMessage { - /// Optimized to avoid reallocations when clients have the same change tick as other clients receiving the + /// Optimized to avoid reallocations when clients have the same update tick as other clients receiving the /// same message. - fn get_bytes(&mut self, change_tick: RepliconTick) -> bincode::Result { + fn get_bytes(&mut self, update_tick: RepliconTick) -> bincode::Result { match self { // Resolve the raw value into a message with serialized tick. Self::Raw(raw) => { let mut bytes = mem::take(raw); bincode::serialize_into( &mut bytes[..mem::size_of::()], - &change_tick, + &update_tick, )?; let bytes = Bytes::from(bytes); *self = Self::Resolved { - tick: change_tick, + tick: update_tick, bytes: bytes.clone(), }; Ok(bytes) } // Get the already-resolved value or reserialize with a different tick. Self::Resolved { tick, bytes } => { - if *tick == change_tick { + if *tick == update_tick { return Ok(bytes.clone()); } let mut new_bytes = Vec::with_capacity(bytes.len()); - bincode::serialize_into(&mut new_bytes, &change_tick)?; + bincode::serialize_into(&mut new_bytes, &update_tick)?; new_bytes.extend_from_slice(&bytes[mem::size_of::()..]); Ok(new_bytes.into()) } @@ -740,7 +740,7 @@ impl BufferedServerEvent { server: &mut RepliconServer, client: &ReplicatedClient, ) -> bincode::Result<()> { - let message = self.message.get_bytes(client.change_tick())?; + let message = self.message.get_bytes(client.update_tick())?; server.send(client.id(), self.channel, message); Ok(()) } @@ -760,10 +760,10 @@ impl BufferedServerEventSet { } } -/// Caches synchronization-dependent server events until they can be sent with an accurate change tick. +/// Caches synchronization-dependent server events until they can be sent with an accurate update tick. /// /// This exists because replication does not scan the world every tick. If a server event is sent in the same -/// tick as a spawn and the event references that spawn, then the server event's change tick needs to be synchronized +/// tick as a spawn and the event references that spawn, then the server event's update tick needs to be synchronized /// with that spawn on the client. We buffer the event until the spawn can be detected. #[derive(Resource, Default)] pub(crate) struct BufferedServerEvents { @@ -881,9 +881,9 @@ struct ServerEventQueue { impl ServerEventQueue { /// Pops the next event that is at least as old as the specified replicon tick. - fn pop_if_le(&mut self, change_tick: RepliconTick) -> Option<(RepliconTick, Bytes)> { + fn pop_if_le(&mut self, update_tick: RepliconTick) -> Option<(RepliconTick, Bytes)> { let (tick, _) = self.list.front()?; - if *tick > change_tick { + if *tick > update_tick { return None; } self.list diff --git a/src/core/replication.rs b/src/core/replication.rs index e1325fbc..7b7f1879 100644 --- a/src/core/replication.rs +++ b/src/core/replication.rs @@ -1,10 +1,10 @@ -pub mod change_message_flags; pub mod command_markers; pub mod deferred_entity; pub mod replicated_clients; pub mod replication_registry; pub mod replication_rules; pub mod track_mutate_messages; +pub mod update_message_flags; use bevy::prelude::*; diff --git a/src/core/replication/replicated_clients.rs b/src/core/replication/replicated_clients.rs index 1f80a46d..11d96291 100644 --- a/src/core/replication/replicated_clients.rs +++ b/src/core/replication/replicated_clients.rs @@ -180,9 +180,9 @@ pub struct ReplicatedClient { /// The last tick in which a replicated entity had an insertion, removal, or gained/lost a component from the /// perspective of the client. /// - /// It should be included in mutate messages and server events to avoid needless waiting for the next change + /// It should be included in mutate messages and server events to avoid needless waiting for the next update /// message to arrive. - change_tick: RepliconTick, + update_tick: RepliconTick, /// Mutate message indices mapped to their info. mutations: HashMap, @@ -199,7 +199,7 @@ impl ReplicatedClient { id, mutation_ticks: Default::default(), visibility: ClientVisibility::new(policy), - change_tick: Default::default(), + update_tick: Default::default(), mutations: Default::default(), next_mutate_index: Default::default(), } @@ -220,15 +220,15 @@ impl ReplicatedClient { &mut self.visibility } - /// Sets the client's change tick. - pub(crate) fn set_change_tick(&mut self, tick: RepliconTick) { - self.change_tick = tick; + /// Sets the client's update tick. + pub(crate) fn set_update_tick(&mut self, tick: RepliconTick) { + self.update_tick = tick; } /// Returns the last tick in which a replicated entity had an insertion, removal, or gained/lost a component from the /// perspective of the client. - pub fn change_tick(&self) -> RepliconTick { - self.change_tick + pub fn update_tick(&self) -> RepliconTick { + self.update_tick } /// Clears all entities for unacknowledged mutate messages, returning them as an iterator. @@ -280,22 +280,22 @@ impl ReplicatedClient { (mutate_index, &mut mutate_info.entities) } - /// Sets the change tick for an entity that is replicated to this client. + /// Sets the mutation tick for an entity that is replicated to this client. /// - /// The change tick is the reference point for determining if components on an entity have changed and - /// need to be replicated. Component changes older than the change limit are assumed to be acked by the client. + /// The mutation tick is the reference point for determining if components on an entity have mutated and + /// need to be replicated. Component mutations older than the update tick are assumed to be acked by the client. pub(crate) fn set_mutation_tick(&mut self, entity: Entity, tick: Tick) { self.mutation_ticks.insert(entity, tick); } - /// Gets the change tick for an entity that is replicated to this client. + /// Gets the mutation tick for an entity that is replicated to this client. pub fn mutation_tick(&self, entity: Entity) -> Option { self.mutation_ticks.get(&entity).copied() } /// Marks mutate message as acknowledged by its index. /// - /// Change tick for all entities from this mutate message will be set to the message tick if it's higher. + /// Mutation tick for all entities from this mutate message will be set to the message tick if it's higher. /// /// Keeps allocated memory in the buffers for reuse. pub(crate) fn ack_mutate_message( diff --git a/src/core/replication/change_message_flags.rs b/src/core/replication/update_message_flags.rs similarity index 53% rename from src/core/replication/change_message_flags.rs rename to src/core/replication/update_message_flags.rs index 834bda3a..2b7fce05 100644 --- a/src/core/replication/change_message_flags.rs +++ b/src/core/replication/update_message_flags.rs @@ -1,11 +1,11 @@ use bitflags::bitflags; bitflags! { - /// Types of data included in the change message if the bit is set. + /// Types of data included in the update message if the bit is set. /// /// Serialized at the beginning of the message. #[derive(Default, Clone, Copy, PartialEq, Eq, Debug)] - pub(crate) struct ChangeMessageFlags: u8 { + pub(crate) struct UpdateMessageFlags: u8 { const MAPPINGS = 0b00000001; const DESPAWNS = 0b00000010; const REMOVALS = 0b00000100; @@ -13,12 +13,12 @@ bitflags! { } } -impl ChangeMessageFlags { +impl UpdateMessageFlags { /// Returns the last set flag in the message. - pub(crate) fn last(self) -> ChangeMessageFlags { + pub(crate) fn last(self) -> UpdateMessageFlags { debug_assert!(!self.is_empty()); let zeroes = u8::BITS - 1 - self.bits().leading_zeros(); - ChangeMessageFlags::from_bits_retain(1 << zeroes) + UpdateMessageFlags::from_bits_retain(1 << zeroes) } } @@ -29,20 +29,20 @@ mod tests { #[test] fn last() { assert_eq!( - ChangeMessageFlags::CHANGES.last(), - ChangeMessageFlags::CHANGES + UpdateMessageFlags::CHANGES.last(), + UpdateMessageFlags::CHANGES ); assert_eq!( - ChangeMessageFlags::MAPPINGS.last(), - ChangeMessageFlags::MAPPINGS + UpdateMessageFlags::MAPPINGS.last(), + UpdateMessageFlags::MAPPINGS ); assert_eq!( - ChangeMessageFlags::all().last(), - ChangeMessageFlags::CHANGES + UpdateMessageFlags::all().last(), + UpdateMessageFlags::CHANGES ); assert_eq!( - (ChangeMessageFlags::DESPAWNS | ChangeMessageFlags::REMOVALS).last(), - ChangeMessageFlags::REMOVALS + (UpdateMessageFlags::DESPAWNS | UpdateMessageFlags::REMOVALS).last(), + UpdateMessageFlags::REMOVALS ); } } diff --git a/src/core/replicon_tick.rs b/src/core/replicon_tick.rs index aeb4996b..c922003f 100644 --- a/src/core/replicon_tick.rs +++ b/src/core/replicon_tick.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; /// /// All operations on it are wrapping. /// -/// See also [`ServerChangeTick`](crate::client::ServerChangeTick) and +/// See also [`ServerUpdateTick`](crate::client::ServerUpdateTick) and /// [`ServerTick`](crate::server::server_tick::ServerTick). #[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] pub struct RepliconTick(u32); diff --git a/src/server.rs b/src/server.rs index bc9ff94e..165e1888 100644 --- a/src/server.rs +++ b/src/server.rs @@ -235,7 +235,7 @@ impl ServerPlugin { mut replicated_clients: ResMut, mut client_buffers: ResMut, ) { - for (client_id, message) in server.receive(ReplicationChannel::Changes) { + for (client_id, message) in server.receive(ReplicationChannel::Updates) { let mut cursor = Cursor::new(&*message); let message_end = message.len() as u64; while cursor.position() < message_end { @@ -362,17 +362,17 @@ fn send_messages( time: &Time, ) -> Result<(), Box> { let mut server_tick_range = None; - for ((change_message, mutate_message), client) in + for ((update_message, mutate_message), client) in messages.iter_mut().zip(replicated_clients.iter_mut()) { - if !change_message.is_empty() { - client.set_change_tick(server_tick); + if !update_message.is_empty() { + client.set_update_tick(server_tick); let server_tick = write_tick_cached(&mut server_tick_range, serialized, server_tick)?; - trace!("sending change message to {:?}", client.id()); - change_message.send(server, client, serialized, server_tick)?; + trace!("sending update message to {:?}", client.id()); + update_message.send(server, client, serialized, server_tick)?; } else { - trace!("no changes to send for {:?}", client.id()); + trace!("no updates to send for {:?}", client.id()); } if !mutate_message.is_empty() || track_mutate_messages { @@ -420,7 +420,7 @@ fn collect_mappings( Ok(()) } -/// Collect entity despawns from this tick into change messages. +/// Collect entity despawns from this tick into update messages. fn collect_despawns( messages: &mut ReplicationMessages, serialized: &mut SerializedData, @@ -447,7 +447,7 @@ fn collect_despawns( Ok(()) } -/// Collects component removals from this tick into change messages. +/// Collects component removals from this tick into update messages. fn collect_removals( messages: &mut ReplicationMessages, serialized: &mut SerializedData, @@ -468,7 +468,7 @@ fn collect_removals( Ok(()) } -/// Collects component changes from this tick into change and mutate messages since the last entity tick. +/// Collects component changes from this tick into update and mutate messages since the last entity tick. fn collect_changes( messages: &mut ReplicationMessages, serialized: &mut SerializedData, @@ -499,11 +499,11 @@ fn collect_changes( for entity in archetype.entities() { let mut entity_range = None; - for ((change_message, mutate_message), client) in + for ((update_message, mutate_message), client) in messages.iter_mut().zip(replicated_clients.iter()) { let visibility = client.visibility().state(entity.id()); - change_message.start_entity_changes(visibility); + update_message.start_entity_changes(visibility); mutate_message.start_entity_mutations(); } @@ -543,17 +543,17 @@ fn collect_changes( component_id, }; let mut component_range = None; - for ((change_message, mutate_message), client) in + for ((update_message, mutate_message), client) in messages.iter_mut().zip(replicated_clients.iter()) { - if change_message.entity_visibility() == Visibility::Hidden { + if update_message.entity_visibility() == Visibility::Hidden { continue; } if let Some(tick) = client .mutation_tick(entity.id()) .filter(|_| !marker_added) - .filter(|_| change_message.entity_visibility() != Visibility::Gained) + .filter(|_| update_message.entity_visibility() != Visibility::Gained) .filter(|_| !ticks.is_added(change_tick.last_run(), change_tick.this_run())) { if ticks.is_changed(tick, change_tick.this_run()) { @@ -577,10 +577,10 @@ fn collect_changes( mutate_message.add_mutated_component(component_range); } } else { - if !change_message.entity_written() { + if !update_message.entity_written() { let entity_range = write_entity_cached(&mut entity_range, serialized, entity.id())?; - change_message.add_changed_entity(entity_range); + update_message.add_changed_entity(entity_range); } let component_range = write_component_cached( &mut component_range, @@ -591,35 +591,35 @@ fn collect_changes( replicated_component, component, )?; - change_message.add_inserted_component(component_range); + update_message.add_inserted_component(component_range); } } } - for ((change_message, mutate_message), client) in + for ((update_message, mutate_message), client) in messages.iter_mut().zip(replicated_clients.iter_mut()) { - let visibility = change_message.entity_visibility(); + let visibility = update_message.entity_visibility(); if visibility == Visibility::Hidden { continue; } let new_entity = marker_added || visibility == Visibility::Gained; if new_entity - || change_message.entity_written() + || update_message.entity_written() || removal_buffer.contains_key(&entity.id()) { // If there is any insertion, removal, or it's a new entity for a client, include all mutations - // into change message and bump the last acknowledged tick to keep entity updates atomic. - change_message.take_mutations(mutate_message); + // into update message and bump the last acknowledged tick to keep entity updates atomic. + update_message.take_mutations(mutate_message); client.set_mutation_tick(entity.id(), change_tick.this_run()); } - if new_entity && !change_message.entity_written() { + if new_entity && !update_message.entity_written() { // Force-write new entity even if it doesn't have any components. let entity_range = write_entity_cached(&mut entity_range, serialized, entity.id())?; - change_message.add_changed_entity(entity_range); + update_message.add_changed_entity(entity_range); } } } diff --git a/src/server/replication_messages.rs b/src/server/replication_messages.rs index af0fb932..c73da478 100644 --- a/src/server/replication_messages.rs +++ b/src/server/replication_messages.rs @@ -1,10 +1,10 @@ -pub(super) mod change_message; mod component_changes; pub(super) mod mutate_message; pub(super) mod serialized_data; +pub(super) mod update_message; -use change_message::ChangeMessage; use mutate_message::MutateMessage; +use update_message::UpdateMessage; /// Accumulates replication messages. /// @@ -13,7 +13,7 @@ use mutate_message::MutateMessage; /// serialized data across messages. #[derive(Default)] pub(crate) struct ReplicationMessages { - messages: Vec<(ChangeMessage, MutateMessage)>, + messages: Vec<(UpdateMessage, MutateMessage)>, len: usize, } @@ -31,8 +31,8 @@ impl ReplicationMessages { self.messages.reserve(additional); for index in 0..clients_count { - if let Some((change_message, mutate_message)) = self.messages.get_mut(index) { - change_message.clear(); + if let Some((update_message, mutate_message)) = self.messages.get_mut(index) { + update_message.clear(); mutate_message.clear(); } else { self.messages.push(Default::default()); @@ -41,7 +41,7 @@ impl ReplicationMessages { } /// Returns iterator over messages for each client. - pub(super) fn iter_mut(&mut self) -> impl Iterator { + pub(super) fn iter_mut(&mut self) -> impl Iterator { self.messages.iter_mut().take(self.len) } } diff --git a/src/server/replication_messages/component_changes.rs b/src/server/replication_messages/component_changes.rs index 30a4fc4e..4f971d43 100644 --- a/src/server/replication_messages/component_changes.rs +++ b/src/server/replication_messages/component_changes.rs @@ -3,7 +3,7 @@ use std::ops::Range; /// Component insertions or mutations for an entity in form of serialized ranges /// from [`SerializedData`](super::serialized_data::SerializedData). /// -/// Used inside [`ChangeMessage`](super::change_message::ChangeMessage) and +/// Used inside [`UpdateMessage`](super::update_message::UpdateMessage) and /// [`MutateMessage`](super::mutate_message::MutateMessage). pub(super) struct ComponentChanges { pub(super) entity: Range, diff --git a/src/server/replication_messages/mutate_message.rs b/src/server/replication_messages/mutate_message.rs index f0982339..0b6e2699 100644 --- a/src/server/replication_messages/mutate_message.rs +++ b/src/server/replication_messages/mutate_message.rs @@ -13,10 +13,10 @@ use crate::core::{ /// A message with replicated component mutations. /// -/// Contains change tick, current tick, mutate index and component mutations since +/// Contains update tick, current tick, mutate index and component mutations since /// the last acknowledged tick for each entity. /// -/// Cannot be applied on the client until the change message matching this message's change tick +/// Cannot be applied on the client until the update message matching this message's update tick /// has been applied to the client world. /// The message will be manually split into packets up to max size, and each packet will be applied /// independently on the client. @@ -43,7 +43,7 @@ pub(crate) struct MutateMessage { /// Components are stored in multiple chunks because some clients may acknowledge mutations, /// while others may not. /// - /// Unlike [`ChangeMessage`](super::change_message::ChangeMessage), we serialize the number + /// Unlike [`UpdateMessage`](super::update_message::UpdateMessage), we serialize the number /// of chunk bytes instead of the number of components. This is because, during deserialization, /// some entities may be skipped if they have already been updated (as mutations are sent until /// the client acknowledges them). @@ -131,9 +131,9 @@ impl MutateMessage { debug_assert_eq!(self.entities.len(), self.mutations.len()); const MAX_COUNT_SIZE: usize = mem::size_of::() + 1; - let mut change_tick = Cursor::new([0; mem::size_of::()]); - bincode::serialize_into(&mut change_tick, &client.change_tick())?; - let mut metadata_size = change_tick.get_ref().len() + server_tick.len(); + let mut update_tick = Cursor::new([0; mem::size_of::()]); + bincode::serialize_into(&mut update_tick, &client.update_tick())?; + let mut metadata_size = update_tick.get_ref().len() + server_tick.len(); if track_mutate_messages { metadata_size += MAX_COUNT_SIZE; } @@ -188,7 +188,7 @@ impl MutateMessage { } let mut message = Vec::with_capacity(message_size); - message.extend_from_slice(change_tick.get_ref()); + message.extend_from_slice(update_tick.get_ref()); message.extend_from_slice(&serialized[server_tick.clone()]); if track_mutate_messages { message.write_varint(messages_count)?; diff --git a/src/server/replication_messages/serialized_data.rs b/src/server/replication_messages/serialized_data.rs index 85a78d1b..41333e75 100644 --- a/src/server/replication_messages/serialized_data.rs +++ b/src/server/replication_messages/serialized_data.rs @@ -16,7 +16,7 @@ use crate::{ /// Single continious buffer that stores serialized data for messages. /// -/// See [`ChangeMessage`](super::change_message::ChangeMessage) and +/// See [`UpdateMessage`](super::update_message::UpdateMessage) and /// [`MutateMessage`](super::mutate_message::MutateMessage). #[derive(Default, Deref, DerefMut)] pub(crate) struct SerializedData(Vec); @@ -102,7 +102,7 @@ impl SerializedData { // A tick >= 2^16 will be 5 bytes: https://docs.rs/bincode/1.3.3/bincode/config/struct.VarintEncoding.html. // At 60 ticks/sec, that will happen after 18 minutes. // So any session over 36 minutes would transmit more total bytes with varint encoding. - // TODO: consider dynamically switching from varint to fixint encoding using one of the `ChangeMessageFlags` when tick sizes get large enough. + // TODO: consider dynamically switching from varint to fixint encoding using one of the `UpdateMessageFlags` when tick sizes get large enough. bincode::serialize_into(&mut self.0, &tick)?; let end = self.len(); diff --git a/src/server/replication_messages/change_message.rs b/src/server/replication_messages/update_message.rs similarity index 91% rename from src/server/replication_messages/change_message.rs rename to src/server/replication_messages/update_message.rs index 8194ab03..2e6b30c4 100644 --- a/src/server/replication_messages/change_message.rs +++ b/src/server/replication_messages/update_message.rs @@ -9,8 +9,8 @@ use super::{ use crate::core::{ channels::ReplicationChannel, replication::{ - change_message_flags::ChangeMessageFlags, replicated_clients::{client_visibility::Visibility, ReplicatedClient}, + update_message_flags::UpdateMessageFlags, }, replicon_server::RepliconServer, }; @@ -23,9 +23,9 @@ use crate::core::{ /// The data is serialized manually and stored in the form of ranges /// from [`SerializedData`]. /// -/// Sent over [`ReplicationChannel::Changes`] channel. +/// Sent over [`ReplicationChannel::Updates`] channel. /// -/// Some data is optional, and their presence is encoded in the [`ChangeMessageFlags`] bitset. +/// Some data is optional, and their presence is encoded in the [`UpdateMessageFlags`] bitset. /// /// To know how much data array takes, we serialize it's length. We use `usize`, /// but we use variable integer encoding, so they are correctly deserialized even @@ -38,7 +38,7 @@ use crate::core::{ /// /// Stored inside [`ReplicationMessages`](super::ReplicationMessages). #[derive(Default)] -pub(crate) struct ChangeMessage { +pub(crate) struct UpdateMessage { /// Mappings for client's pre-spawned entities. /// /// Serialized as single continuous chunk of entity pairs. @@ -76,7 +76,7 @@ pub(crate) struct ChangeMessage { /// while previously connected clients only need the components spawned during this tick. /// /// Usually mutations are stored in [`MutateMessage`], but if an entity has any insertions or removal, - /// or the entity just became visible for a client, we serialize it as part of the change message to keep entity updates atomic. + /// or the entity just became visible for a client, we serialize it as part of the update message to keep entity updates atomic. changes: Vec, /// Visibility of the entity for which component changes are being written. @@ -92,7 +92,7 @@ pub(crate) struct ChangeMessage { buffer: Vec>>, } -impl ChangeMessage { +impl UpdateMessage { pub(crate) fn set_mappings(&mut self, mappings: Range, len: usize) { self.mappings = mappings; self.mappings_len = len; @@ -208,22 +208,22 @@ impl ChangeMessage { let last_flag = flags.last(); // Precalculate size first to avoid extra allocations. - let mut message_size = size_of::() + server_tick.len(); + let mut message_size = size_of::() + server_tick.len(); for (_, flag) in flags.iter_names() { match flag { - ChangeMessageFlags::MAPPINGS => { + UpdateMessageFlags::MAPPINGS => { if flag != last_flag { message_size += self.mappings_len.required_space(); } message_size += self.mappings.len(); } - ChangeMessageFlags::DESPAWNS => { + UpdateMessageFlags::DESPAWNS => { if flag != last_flag { message_size += self.despawns_len.required_space(); } message_size += self.despawns.iter().map(|range| range.len()).sum::(); } - ChangeMessageFlags::REMOVALS => { + UpdateMessageFlags::REMOVALS => { if flag != last_flag { message_size += self.removals.len().required_space(); } @@ -233,7 +233,7 @@ impl ChangeMessage { .map(|removals| removals.size()) .sum::(); } - ChangeMessageFlags::CHANGES => { + UpdateMessageFlags::CHANGES => { debug_assert_eq!(flag, last_flag); message_size += self .changes @@ -254,7 +254,7 @@ impl ChangeMessage { message.extend_from_slice(&serialized[server_tick]); for (_, flag) in flags.iter_names() { match flag { - ChangeMessageFlags::MAPPINGS => { + UpdateMessageFlags::MAPPINGS => { // Always write size since the message can't have only mappings. // Otherwise this would mean that the client already received the mapped // entity and it's already mapped or server sends an invisible entity which @@ -263,7 +263,7 @@ impl ChangeMessage { message.write_varint(self.mappings_len)?; message.extend_from_slice(&serialized[self.mappings.clone()]); } - ChangeMessageFlags::DESPAWNS => { + UpdateMessageFlags::DESPAWNS => { if flag != last_flag { message.write_varint(self.despawns_len)?; } @@ -271,7 +271,7 @@ impl ChangeMessage { message.extend_from_slice(&serialized[range.clone()]); } } - ChangeMessageFlags::REMOVALS => { + UpdateMessageFlags::REMOVALS => { if flag != last_flag { message.write_varint(self.removals.len())?; } @@ -281,7 +281,7 @@ impl ChangeMessage { message.extend_from_slice(&serialized[removals.fn_ids.clone()]); } } - ChangeMessageFlags::CHANGES => { + UpdateMessageFlags::CHANGES => { // Changes are always last, don't write len for it. for changes in &self.changes { message.extend_from_slice(&serialized[changes.entity.clone()]); @@ -297,25 +297,25 @@ impl ChangeMessage { debug_assert_eq!(message.len(), message_size); - server.send(client.id(), ReplicationChannel::Changes, message); + server.send(client.id(), ReplicationChannel::Updates, message); Ok(()) } - fn flags(&self) -> ChangeMessageFlags { - let mut flags = ChangeMessageFlags::default(); + fn flags(&self) -> UpdateMessageFlags { + let mut flags = UpdateMessageFlags::default(); if !self.mappings.is_empty() { - flags |= ChangeMessageFlags::MAPPINGS; + flags |= UpdateMessageFlags::MAPPINGS; } if !self.despawns.is_empty() { - flags |= ChangeMessageFlags::DESPAWNS; + flags |= UpdateMessageFlags::DESPAWNS; } if !self.removals.is_empty() { - flags |= ChangeMessageFlags::REMOVALS; + flags |= UpdateMessageFlags::REMOVALS; } if !self.changes.is_empty() { - flags |= ChangeMessageFlags::CHANGES; + flags |= UpdateMessageFlags::CHANGES; } flags diff --git a/src/server/server_tick.rs b/src/server/server_tick.rs index c327b4f4..fe50cbb3 100644 --- a/src/server/server_tick.rs +++ b/src/server/server_tick.rs @@ -14,7 +14,7 @@ use crate::core::replicon_tick::RepliconTick; /// This value can be used to represent your simulation step, and is made available to the client in /// the custom deserialization, despawn, and component removal functions. /// -/// See [`ServerChangeTick`](crate::client::ServerChangeTick) for tracking the last received +/// See [`ServerUpdateTick`](crate::client::ServerUpdateTick) for tracking the last received /// tick on clients. #[derive(Clone, Copy, Deref, Debug, Default, Deserialize, Resource, Serialize)] pub struct ServerTick(RepliconTick); diff --git a/tests/connection.rs b/tests/connection.rs index 1f2b7d63..d85694b6 100644 --- a/tests/connection.rs +++ b/tests/connection.rs @@ -21,7 +21,7 @@ fn client_to_server() { client_id: Some(CLIENT_ID), }); for &message in MESSAGES { - client.send(ReplicationChannel::Changes, message); + client.send(ReplicationChannel::Updates, message); } let mut server = server_app.world_mut().resource_mut::(); @@ -32,7 +32,7 @@ fn client_to_server() { } let messages: Vec<_> = server - .receive(ReplicationChannel::Changes) + .receive(ReplicationChannel::Updates) .map(|(_, message)| message) .collect(); assert_eq!(messages, MESSAGES); @@ -53,7 +53,7 @@ fn server_to_client() { let mut server = server_app.world_mut().resource_mut::(); server.set_running(true); for &message in MESSAGES { - server.send(CLIENT_ID, ReplicationChannel::Changes, message); + server.send(CLIENT_ID, ReplicationChannel::Updates, message); } let mut client = client_app.world_mut().resource_mut::(); @@ -65,7 +65,7 @@ fn server_to_client() { client.insert_received(channel_id, message); } - let messages: Vec<_> = client.receive(ReplicationChannel::Changes).collect(); + let messages: Vec<_> = client.receive(ReplicationChannel::Updates).collect(); assert_eq!(messages, MESSAGES); } @@ -110,13 +110,13 @@ fn client_cleanup_on_disconnect() { let mut client = app.world_mut().resource_mut::(); client.set_status(RepliconClientStatus::Connected { client_id: None }); - client.send(ReplicationChannel::Changes, Vec::new()); - client.insert_received(ReplicationChannel::Changes, Vec::new()); + client.send(ReplicationChannel::Updates, Vec::new()); + client.insert_received(ReplicationChannel::Updates, Vec::new()); client.set_status(RepliconClientStatus::Disconnected); assert_eq!(client.drain_sent().count(), 0); - assert_eq!(client.receive(ReplicationChannel::Changes).count(), 0); + assert_eq!(client.receive(ReplicationChannel::Updates).count(), 0); app.update(); } @@ -138,13 +138,13 @@ fn server_cleanup_on_stop() { server.set_running(true); const DUMMY_CLIENT_ID: ClientId = ClientId::new(1); - server.send(DUMMY_CLIENT_ID, ReplicationChannel::Changes, Vec::new()); - server.insert_received(DUMMY_CLIENT_ID, ReplicationChannel::Changes, Vec::new()); + server.send(DUMMY_CLIENT_ID, ReplicationChannel::Updates, Vec::new()); + server.insert_received(DUMMY_CLIENT_ID, ReplicationChannel::Updates, Vec::new()); server.set_running(false); assert_eq!(server.drain_sent().count(), 0); - assert_eq!(server.receive(ReplicationChannel::Changes).count(), 0); + assert_eq!(server.receive(ReplicationChannel::Updates).count(), 0); app.update(); @@ -166,11 +166,11 @@ fn client_disconnected() { let mut client = app.world_mut().resource_mut::(); - client.send(ReplicationChannel::Changes, Vec::new()); - client.insert_received(ReplicationChannel::Changes, Vec::new()); + client.send(ReplicationChannel::Updates, Vec::new()); + client.insert_received(ReplicationChannel::Updates, Vec::new()); assert_eq!(client.drain_sent().count(), 0); - assert_eq!(client.receive(ReplicationChannel::Changes).count(), 0); + assert_eq!(client.receive(ReplicationChannel::Updates).count(), 0); app.update(); } @@ -192,11 +192,11 @@ fn server_inactive() { const DUMMY_CLIENT_ID: ClientId = ClientId::new(1); - server.send(DUMMY_CLIENT_ID, ReplicationChannel::Changes, Vec::new()); - server.insert_received(DUMMY_CLIENT_ID, ReplicationChannel::Changes, Vec::new()); + server.send(DUMMY_CLIENT_ID, ReplicationChannel::Updates, Vec::new()); + server.insert_received(DUMMY_CLIENT_ID, ReplicationChannel::Updates, Vec::new()); assert_eq!(server.drain_sent().count(), 0); - assert_eq!(server.receive(ReplicationChannel::Changes).count(), 0); + assert_eq!(server.receive(ReplicationChannel::Updates).count(), 0); app.update(); diff --git a/tests/mutations.rs b/tests/mutations.rs index 8eb1902a..0a588a69 100644 --- a/tests/mutations.rs +++ b/tests/mutations.rs @@ -4,7 +4,7 @@ use bevy::{ecs::entity::MapEntities, prelude::*, utils::Duration}; use bevy_replicon::{ client::{ confirm_history::{ConfirmHistory, EntityReplicated}, - ServerChangeTick, + ServerUpdateTick, }, core::{ replication::{ @@ -748,10 +748,10 @@ fn buffering() { client_app.update(); server_app.exchange_with_client(&mut client_app); - // Artificially reset the change tick to force the next received mutation to be buffered. - let mut change_tick = client_app.world_mut().resource_mut::(); - let previous_tick = *change_tick; - *change_tick = Default::default(); + // Artificially reset the update tick to force the next received mutation to be buffered. + let mut update_tick = client_app.world_mut().resource_mut::(); + let previous_tick = *update_tick; + *update_tick = Default::default(); let mut component = server_app .world_mut() .get_mut::(server_entity) @@ -769,8 +769,8 @@ fn buffering() { .single(client_app.world()); assert!(!component.0, "client should buffer the mutation"); - // Restore the change tick to let the buffered mutation apply - *client_app.world_mut().resource_mut::() = previous_tick; + // Restore the update tick to let the buffered mutation apply + *client_app.world_mut().resource_mut::() = previous_tick; server_app.update(); server_app.exchange_with_client(&mut client_app); diff --git a/tests/server_event.rs b/tests/server_event.rs index 322ec856..db129764 100644 --- a/tests/server_event.rs +++ b/tests/server_event.rs @@ -4,7 +4,7 @@ use bevy::{ time::TimePlugin, }; use bevy_replicon::{ - client::ServerChangeTick, core::server_entity_map::ServerEntityMap, prelude::*, + client::ServerUpdateTick, core::server_entity_map::ServerEntityMap, prelude::*, server::server_tick::ServerTick, test_app::ServerTestAppExt, }; use serde::{Deserialize, Serialize}; @@ -264,10 +264,10 @@ fn event_queue() { client_app.update(); server_app.exchange_with_client(&mut client_app); - // Artificially reset the change tick to force the next received event to be queued. - let mut change_tick = client_app.world_mut().resource_mut::(); - let previous_tick = *change_tick; - *change_tick = Default::default(); + // Artificially reset the update tick to force the next received event to be queued. + let mut update_tick = client_app.world_mut().resource_mut::(); + let previous_tick = *update_tick; + *update_tick = Default::default(); server_app.world_mut().send_event(ToClients { mode: SendMode::Broadcast, event: DummyEvent, @@ -280,8 +280,8 @@ fn event_queue() { let events = client_app.world().resource::>(); assert!(events.is_empty()); - // Restore the change tick to receive the event. - *client_app.world_mut().resource_mut::() = previous_tick; + // Restore the update tick to receive the event. + *client_app.world_mut().resource_mut::() = previous_tick; client_app.update(); @@ -318,10 +318,10 @@ fn event_queue_and_mapping() { client_app.update(); server_app.exchange_with_client(&mut client_app); - // Artificially reset the change tick to force the next received event to be queued. - let mut change_tick = client_app.world_mut().resource_mut::(); - let previous_tick = *change_tick; - *change_tick = Default::default(); + // Artificially reset the update tick to force the next received event to be queued. + let mut update_tick = client_app.world_mut().resource_mut::(); + let previous_tick = *update_tick; + *update_tick = Default::default(); server_app.world_mut().send_event(ToClients { mode: SendMode::Broadcast, event: EntityEvent(server_entity), @@ -334,8 +334,8 @@ fn event_queue_and_mapping() { let events = client_app.world().resource::>(); assert!(events.is_empty()); - // Restore the change tick to receive the event. - *client_app.world_mut().resource_mut::() = previous_tick; + // Restore the update tick to receive the event. + *client_app.world_mut().resource_mut::() = previous_tick; client_app.update(); @@ -374,10 +374,10 @@ fn multiple_event_queues() { client_app.update(); server_app.exchange_with_client(&mut client_app); - // Artificially reset the change tick to force the next received event to be queued. - let mut change_tick = client_app.world_mut().resource_mut::(); - let previous_tick = *change_tick; - *change_tick = Default::default(); + // Artificially reset the update tick to force the next received event to be queued. + let mut update_tick = client_app.world_mut().resource_mut::(); + let previous_tick = *update_tick; + *update_tick = Default::default(); server_app.world_mut().send_event(ToClients { mode: SendMode::Broadcast, event: DummyEvent, @@ -397,8 +397,8 @@ fn multiple_event_queues() { let mapped_events = client_app.world().resource::>(); assert!(mapped_events.is_empty()); - // Restore the change tick to receive the event. - *client_app.world_mut().resource_mut::() = previous_tick; + // Restore the update tick to receive the event. + *client_app.world_mut().resource_mut::() = previous_tick; client_app.update(); @@ -435,10 +435,10 @@ fn independent() { client_app.update(); server_app.exchange_with_client(&mut client_app); - // Artificially reset the change tick. + // Artificially reset the update tick. // Normal events would be queued and not triggered yet, // but our independent event should be triggered immediately. - *client_app.world_mut().resource_mut::() = Default::default(); + *client_app.world_mut().resource_mut::() = Default::default(); let client = client_app.world().resource::(); let client_id = client.id().unwrap(); @@ -570,7 +570,7 @@ fn different_ticks() { server_app.exchange_with_client(&mut client_app1); // Connect client 2 later to make it have a higher replicon tick than client 1, - // since only client 1 will recieve a change message here. + // since only client 1 will recieve a update message here. server_app.connect_client(&mut client_app2); server_app.world_mut().send_event(ToClients { @@ -578,7 +578,7 @@ fn different_ticks() { event: DummyEvent, }); - // If any client does not have a replicon tick >= the change tick associated with this event, + // If any client does not have a replicon tick >= the update tick associated with this event, // then they will not receive the event until their replicon tick is updated. server_app.update(); server_app.exchange_with_client(&mut client_app1);