Skip to content

Commit

Permalink
call it ClientEntityMap for server
Browse files Browse the repository at this point in the history
  • Loading branch information
RJ committed Oct 5, 2023
1 parent fb3b7dc commit 17cf797
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -54,7 +54,7 @@ impl Plugin for ServerPlugin {
))
.init_resource::<AckedTicks>()
.init_resource::<RepliconTick>()
.init_resource::<RepliconEntityMap>()
.init_resource::<ClientEntityMap>()
.configure_set(
PreUpdate,
ServerSet::Receive.after(NetcodeServerPlugin::update_system),
Expand Down Expand Up @@ -116,7 +116,7 @@ impl ServerPlugin {
fn acks_receiving_system(
mut acked_ticks: ResMut<AckedTicks>,
mut server: ResMut<RenetServer>,
mut predictions: ResMut<RepliconEntityMap>,
mut predictions: ResMut<ClientEntityMap>,
) {
for client_id in server.clients_id() {
while let Some(message) = server.receive_message(client_id, REPLICATION_CHANNEL_ID) {
Expand Down Expand Up @@ -160,7 +160,7 @@ impl ServerPlugin {
despawn_tracker: Res<DespawnTracker>,
replicon_tick: Res<RepliconTick>,
removal_trackers: Query<(Entity, &RemovalTracker)>,
predictions: Res<RepliconEntityMap>,
predictions: Res<ClientEntityMap>,
) -> Result<(), bincode::Error> {
let mut acked_ticks = set.p2();
acked_ticks.register_tick(*replicon_tick, change_tick.this_run());
Expand Down Expand Up @@ -223,7 +223,7 @@ fn prepare_buffers<'a>(
fn collect_mappings(
buffers: &mut [ReplicationBuffer],
acked_ticks: &ResMut<AckedTicks>,
predictions: &Res<RepliconEntityMap>,
predictions: &Res<ClientEntityMap>,
) -> Result<(), bincode::Error> {
for buffer in &mut *buffers {
// Include all entity mappings since the last acknowledged tick.
Expand Down
10 changes: 5 additions & 5 deletions src/server/replicon_entity_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
///
Expand All @@ -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`].
Expand All @@ -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<RepliconEntityMap>, tick: Res<RepliconTick>) {
/// fn apply_inputs_system(mut entity_map: ResMut<ClientEntityMap>, tick: Res<RepliconTick>) {
/// // ...
/// if player_input.pressed_shoot() {
/// let server_entity = commands.spawn((Bullet, Replication, Etc)).id();
Expand All @@ -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<u64, Vec<EntityMapping>>,
}
pub(crate) type EntityMapping = (RepliconTick, ServerEntity, ClientEntity);
Expand All @@ -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`].
Expand Down
2 changes: 1 addition & 1 deletion tests/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn spawn_prediction_replication() {
// and registers the client's predicted entity
server_app
.world
.resource_scope(|_world, mut pt: Mut<RepliconEntityMap>| {
.resource_scope(|_world, mut pt: Mut<ClientEntityMap>| {
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,
Expand Down

0 comments on commit 17cf797

Please sign in to comment.