Skip to content

Commit

Permalink
avoid log (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
cBournhonesque authored Jan 8, 2025
1 parent 5e26ba9 commit 37f0b54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
7 changes: 7 additions & 0 deletions lightyear/src/client/input/leafwing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,13 @@ fn prepare_input_message<A: LeafwingUserAction>(
// maybe if it's pre-predicted, we send the original entity (pre-predicted), and the server will apply the conversion
// on their end?
if pre_predicted.is_some() {
// wait until the client receives the PrePredicted entity confirmation to send inputs
// otherwise we get failed entity_map logs
// TODO: the problem is that we wait until we have received the server answer. Ideally we would like
// to wait until the server has received the PrePredicted entity
if predicted.is_none() {
continue;
}
trace!(
?tick,
"sending inputs for pre-predicted entity! Local client entity: {:?}",
Expand Down
1 change: 0 additions & 1 deletion lightyear/src/client/prediction/pre_prediction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ impl PrePredictionPlugin {
.as_ref()
.unwrap()
};
let confirmed = trigger.entity();
// PrePredicted was replicated from the server:
// When we receive an update from the server that confirms a pre-predicted entity,
// we will add the Predicted component
Expand Down
22 changes: 10 additions & 12 deletions lightyear/src/server/prediction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub(crate) fn compute_hash(
pub(crate) fn handle_pre_predicted(
trigger: Trigger<OnAdd, PrePredicted>,
mut commands: Commands,
mut manager: ResMut<ServerConnectionManager>,
// add `With<Replicated>` bound for host-server mode; so that we don't trigger this system
// for local client entities
q: Query<(Entity, &PrePredicted, &Replicated)>,
Expand All @@ -71,20 +72,17 @@ pub(crate) fn handle_pre_predicted(
replicated.from
);
let sending_client = replicated.from.unwrap();
let confirmed_entity = pre_predicted.confirmed_entity.unwrap();
// update the mapping so that when we send updates, the server entity gets mapped
// to the client's confirmed entity
manager
.connection_mut(sending_client)
.unwrap()
.replication_receiver
.remote_entity_map
.insert(confirmed_entity, local_entity);
commands
.entity(local_entity)
.transfer_authority(AuthorityPeer::Server);
let confirmed_entity = pre_predicted.confirmed_entity.unwrap();
commands.queue(move |world: &mut World| {
// update the mapping so that when we send updates, the server entity gets mapped
// to the client's confirmed entity
world
.resource_mut::<ServerConnectionManager>()
.connection_mut(sending_client)
.unwrap()
.replication_receiver
.remote_entity_map
.insert(confirmed_entity, local_entity)
})
}
}

0 comments on commit 37f0b54

Please sign in to comment.