From 469e6940ef68d712f0fc022adc705d3efce7fb7b Mon Sep 17 00:00:00 2001 From: Caspar Krieger Date: Sat, 14 Dec 2024 14:29:43 +0800 Subject: [PATCH] Remove GGRS-specific builders and ggrs impl for WebRtcSocket To create GGRS sockets, users can still create new sockets by specifying ChannelConfig::unreliable() and using WebRtcSocket::take_channel() to detach the channel so it can be owned by GGRS. This makes it clearer that there's nothing special about GGRS sockets. --- bevy_matchbox/src/signaling.rs | 6 +- bevy_matchbox/src/socket.rs | 17 ----- examples/bevy_ggrs/src/box_game.rs | 15 +++-- examples/bevy_ggrs/src/main.rs | 8 ++- matchbox_socket/src/ggrs_socket.rs | 71 +++++---------------- matchbox_socket/src/lib.rs | 2 - matchbox_socket/src/webrtc_socket/socket.rs | 39 +++++++---- 7 files changed, 59 insertions(+), 99 deletions(-) diff --git a/bevy_matchbox/src/signaling.rs b/bevy_matchbox/src/signaling.rs index f1ab5796..9c1e2a11 100644 --- a/bevy_matchbox/src/signaling.rs +++ b/bevy_matchbox/src/signaling.rs @@ -163,8 +163,10 @@ impl MatchboxServer { #[cfg(test)] mod tests { - use crate::matchbox_signaling::topologies::client_server::{ClientServer, ClientServerState}; - use crate::prelude::*; + use crate::{ + matchbox_signaling::topologies::client_server::{ClientServer, ClientServerState}, + prelude::*, + }; use bevy::prelude::*; use std::net::Ipv4Addr; diff --git a/bevy_matchbox/src/socket.rs b/bevy_matchbox/src/socket.rs index 4469b154..e4e1c457 100644 --- a/bevy_matchbox/src/socket.rs +++ b/bevy_matchbox/src/socket.rs @@ -173,21 +173,4 @@ impl MatchboxSocket { pub fn new_reliable(room_url: impl Into) -> MatchboxSocket { Self::from(WebRtcSocket::new_reliable(room_url)) } - - /// Create a new socket with a single ggrs-compatible channel - /// - /// ```rust - /// use bevy_matchbox::prelude::*; - /// use bevy::prelude::*; - /// - /// fn open_channel_system(mut commands: Commands) { - /// let room_url = "wss://matchbox.example.com"; - /// let socket = MatchboxSocket::new_ggrs(room_url); - /// commands.spawn(socket); - /// } - /// ``` - #[cfg(feature = "ggrs")] - pub fn new_ggrs(room_url: impl Into) -> MatchboxSocket { - Self::from(WebRtcSocket::new_ggrs(room_url)) - } } diff --git a/examples/bevy_ggrs/src/box_game.rs b/examples/bevy_ggrs/src/box_game.rs index 3de7ca71..5aa5090c 100644 --- a/examples/bevy_ggrs/src/box_game.rs +++ b/examples/bevy_ggrs/src/box_game.rs @@ -24,8 +24,8 @@ const FRICTION: f32 = 0.0018; const PLANE_SIZE: f32 = 5.0; const CUBE_SIZE: f32 = 0.2; -// You need to define a config struct to bundle all the generics of GGRS. bevy_ggrs provides a sensible default in `GgrsConfig`. -// (optional) You can define a type here for brevity. +// You need to define a config struct to bundle all the generics of GGRS. bevy_ggrs provides a +// sensible default in `GgrsConfig`. (optional) You can define a type here for brevity. pub type BoxConfig = GgrsConfig; #[repr(C)] @@ -58,7 +58,8 @@ pub struct FrameCount { pub frame: u32, } -/// Collects player inputs during [`ReadInputs`](`bevy_ggrs::ReadInputs`) and creates a [`LocalInputs`] resource. +/// Collects player inputs during [`ReadInputs`](`bevy_ggrs::ReadInputs`) and creates a +/// [`LocalInputs`] resource. pub fn read_local_inputs( mut commands: Commands, keyboard_input: Res>, @@ -154,8 +155,9 @@ pub fn setup_scene( } // Example system, manipulating a resource, will be added to the rollback schedule. -// Increases the frame count by 1 every update step. If loading and saving resources works correctly, -// you should see this resource rolling back, counting back up and finally increasing by 1 every update step +// Increases the frame count by 1 every update step. If loading and saving resources works +// correctly, you should see this resource rolling back, counting back up and finally increasing by +// 1 every update step #[allow(dead_code)] pub fn increase_frame_system(mut frame_count: ResMut) { frame_count.frame += 1; @@ -167,7 +169,8 @@ pub fn increase_frame_system(mut frame_count: ResMut) { #[allow(dead_code)] pub fn move_cube_system( mut query: Query<(&mut Transform, &mut Velocity, &Player), With>, - // ^------^ Added by `add_rollback` earlier + // ^------^ Added by + // `add_rollback` earlier inputs: Res>, // Thanks to RollbackTimePlugin, this is rollback safe time: Res