diff --git a/src/lib.rs b/src/lib.rs index 36c0e967..bcc242f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,7 +148,7 @@ for the tick frame, which is in the past, then resimulate. ### Mapping to existing client entities If you want to spawn entities on the client before the server replicates the spawn back -to the client, and use the existing client entity to replicate data into, see [`RepliconEntityMap`] +to the client, and use the existing client entity to replicate data into, see [`ClientEntityMap`] This can be useful for certain types of game. Eg, spawning bullets on the client immediately without waiting on replication. @@ -408,7 +408,7 @@ pub mod prelude { NetworkChannels, RepliconCorePlugin, }, server::{ - has_authority, AckedTicks, RepliconEntityMap, ServerPlugin, ServerSet, TickPolicy, + has_authority, AckedTicks, ClientEntityMap, ServerPlugin, ServerSet, TickPolicy, SERVER_ID, }, ReplicationPlugins, diff --git a/src/server.rs b/src/server.rs index ba584def..89814762 100644 --- a/src/server.rs +++ b/src/server.rs @@ -28,7 +28,7 @@ use crate::replicon_core::{ use despawn_tracker::{DespawnTracker, DespawnTrackerPlugin}; use removal_tracker::{RemovalTracker, RemovalTrackerPlugin}; use replication_buffer::ReplicationBuffer; -pub use replicon_entity_map::RepliconEntityMap; +pub use replicon_entity_map::ClientEntityMap; pub const SERVER_ID: u64 = 0; @@ -54,7 +54,7 @@ impl Plugin for ServerPlugin { )) .init_resource::() .init_resource::() - .init_resource::() + .init_resource::() .configure_set( PreUpdate, ServerSet::Receive.after(NetcodeServerPlugin::update_system), @@ -116,7 +116,7 @@ impl ServerPlugin { fn acks_receiving_system( mut acked_ticks: ResMut, mut server: ResMut, - mut predictions: ResMut, + mut predictions: ResMut, ) { for client_id in server.clients_id() { while let Some(message) = server.receive_message(client_id, REPLICATION_CHANNEL_ID) { @@ -160,7 +160,7 @@ impl ServerPlugin { despawn_tracker: Res, replicon_tick: Res, removal_trackers: Query<(Entity, &RemovalTracker)>, - predictions: Res, + predictions: Res, ) -> Result<(), bincode::Error> { let mut acked_ticks = set.p2(); acked_ticks.register_tick(*replicon_tick, change_tick.this_run()); @@ -223,7 +223,7 @@ fn prepare_buffers<'a>( fn collect_mappings( buffers: &mut [ReplicationBuffer], acked_ticks: &ResMut, - predictions: &Res, + predictions: &Res, ) -> Result<(), bincode::Error> { for buffer in &mut *buffers { // Include all entity mappings since the last acknowledged tick. diff --git a/src/server/replicon_entity_map.rs b/src/server/replicon_entity_map.rs index edd68879..1df8084e 100644 --- a/src/server/replicon_entity_map.rs +++ b/src/server/replicon_entity_map.rs @@ -4,7 +4,7 @@ use bevy::{ }; use super::RepliconTick; -/// ['RepliconEntityMap'] is a resource that exists on the server for mapping server entities to +/// ['ClientEntityMap'] is a resource that exists on the server for mapping server entities to /// entities that clients have already spawned. The mappings are sent to clients and injected into /// the client's [`crate::client::NetworkEntityMap`]. /// @@ -14,7 +14,7 @@ use super::RepliconTick; /// a brand new bullet on the client. /// /// In this situation, the server can write the client `Entity` it sent (in your game's custom -/// protocol) into the [`RepliconEntityMap`], associating it with the newly spawned server entity. +/// protocol) into the [`ClientEntityMap`], associating it with the newly spawned server entity. /// /// Replication packets will send a list of such mappings /// to clients, which will be inserted into the client's [`crate::client::NetworkEntityMap`]. @@ -29,7 +29,7 @@ use super::RepliconTick; /// send_shoot_command_to_server(client_predicted_entity); /// } /// // on server: -/// fn apply_inputs_system(mut entity_map: ResMut, tick: Res) { +/// fn apply_inputs_system(mut entity_map: ResMut, tick: Res) { /// // ... /// if player_input.pressed_shoot() { /// let server_entity = commands.spawn((Bullet, Replication, Etc)).id(); @@ -52,7 +52,7 @@ use super::RepliconTick; /// just the same as when no client prediction is provided. /// #[derive(Resource, Debug, Default)] -pub struct RepliconEntityMap { +pub struct ClientEntityMap { mappings: HashMap>, } pub(crate) type EntityMapping = (RepliconTick, ServerEntity, ClientEntity); @@ -61,7 +61,7 @@ pub(crate) type EntityMapping = (RepliconTick, ServerEntity, ClientEntity); pub(crate) type ServerEntity = Entity; pub(crate) type ClientEntity = Entity; -impl RepliconEntityMap { +impl ClientEntityMap { /// Register that the server spawned `server_entity` as a result of `client_id` sending a /// command which included a `client_entity` they already spawned. This will be sent and added /// to the client's [`crate::client::NetworkEntityMap`]. diff --git a/tests/replication.rs b/tests/replication.rs index 3c32d299..948e6033 100644 --- a/tests/replication.rs +++ b/tests/replication.rs @@ -142,7 +142,7 @@ fn spawn_prediction_replication() { // and registers the client's predicted entity server_app .world - .resource_scope(|_world, mut pt: Mut| { + .resource_scope(|_world, mut pt: Mut| { pt.insert(client_id, server_entity, client_predicted_entity, tick) }); // an edge case to test is when the server spawns an entity that has a predicted entity,