aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHenauxg <19689618+Henauxg@users.noreply.github.com>2023-01-20 13:23:40 +0100
committerHenauxg <19689618+Henauxg@users.noreply.github.com>2023-01-20 13:23:40 +0100
commitff2809001a09eb56e53a1235d1d403b58a8dea4c (patch)
tree3ba2397a039a052128c0da07caf4305a5f6a38ef /examples
parentef3e2df0e2850cd2b5de976bd2f9382c258a4e1e (diff)
[example:breakout] Make use of Unreliable and UnorderedReliable channels
Diffstat (limited to 'examples')
-rw-r--r--examples/breakout/server.rs31
1 files changed, 19 insertions, 12 deletions
diff --git a/examples/breakout/server.rs b/examples/breakout/server.rs
index 4ad2538..4164f7e 100644
--- a/examples/breakout/server.rs
+++ b/examples/breakout/server.rs
@@ -12,7 +12,7 @@ use bevy_quinnet::{
server::{
certificate::CertificateRetrievalMode, ConnectionEvent, Server, ServerConfigurationData,
},
- shared::ClientId,
+ shared::{channel::ChannelId, ClientId},
};
use crate::{
@@ -158,8 +158,9 @@ pub(crate) fn update_paddles(
paddle_transform.translation.x = new_paddle_position.clamp(left_bound, right_bound);
- server.endpoint().try_send_group_message(
+ server.endpoint().try_send_group_message_on(
players.map.keys().into_iter(),
+ ChannelId::Unreliable,
ServerMessage::PaddleMoved {
entity: paddle_entity,
position: paddle_transform.translation,
@@ -198,10 +199,13 @@ pub(crate) fn check_for_collisions(
if let Some(brick) = maybe_brick {
commands.entity(collider_entity).despawn();
- endpoint.try_broadcast_message(ServerMessage::BrickDestroyed {
- by_client_id: ball.last_hit_by,
- brick_id: brick.0,
- });
+ endpoint.try_broadcast_message_on(
+ ChannelId::UnorderedReliable,
+ ServerMessage::BrickDestroyed {
+ by_client_id: ball.last_hit_by,
+ brick_id: brick.0,
+ },
+ );
}
// reflect the ball when it collides
@@ -228,12 +232,15 @@ pub(crate) fn check_for_collisions(
ball_velocity.y = -ball_velocity.y;
}
- endpoint.try_broadcast_message(ServerMessage::BallCollided {
- owner_client_id: ball.last_hit_by,
- entity: ball_entity,
- position: ball_transform.translation,
- velocity: ball_velocity.0,
- });
+ endpoint.try_broadcast_message_on(
+ ChannelId::UnorderedReliable,
+ ServerMessage::BallCollided {
+ owner_client_id: ball.last_hit_by,
+ entity: ball_entity,
+ position: ball_transform.translation,
+ velocity: ball_velocity.0,
+ },
+ );
}
}
}