aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--examples/breakout/server.rs31
2 files changed, 21 insertions, 12 deletions
diff --git a/README.md b/README.md
index 962f33a..b47218c 100644
--- a/README.md
+++ b/README.md
@@ -300,6 +300,8 @@ This demo is a modification of the classic [Bevy breakout](https://bevyengine.or
It hosts a local server from inside a client, instead of a dedicated headless server as in the chat demo. You can find a [server module](examples/breakout/server.rs), a [client module](examples/breakout/client.rs), a shared [protocol](examples/breakout/protocol.rs) and the [bevy app schedule](examples/breakout/breakout.rs).
+It also makes uses of [`Channels`](#channels). The server broadcasts the paddle position every tick via the `PaddleMoved` message on an `Unreliable` channel, the `BrickDestroyed` and `BallCollided` events are emitted on an `UnorderedReliable` channel, while the game setup and start are using the default `OrdrerdReliable` channel.
+
Start two clients with `cargo run --example breakout`, "Host" on one and "Join" on the other.
![breakout_versus_demo_short](https://user-images.githubusercontent.com/19689618/199804335-17df365c-32aa-49b1-94f1-11b8c7162ae3.gif)
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,
+ },
+ );
}
}
}