diff --git a/CHANGELOG.md b/CHANGELOG.md index 430d221..643b020 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,20 +4,29 @@ This changelog follows the patterns described here: now properly documents all features diff --git a/Cargo.toml b/Cargo.toml index db40cf5..218ed2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,19 @@ resolver = "2" [workspace.package] edition = "2021" -version = "0.8.12" -license = "MIT/Apache-2.0" +version = "0.9.0" +license = "MIT OR Apache-2.0" description = "A client-server library designed over WebRTC for Bevy" repository = "https://github.com/vectorgameexperts/bevy-rtc" authors = ["Spencer C. Imbleau"] -keywords = ["gamedev"] +keywords = ["bevy", "webrtc", "networking", "wasm"] +categories = [ + "network-programming", + "game-development", + "wasm", + "web-programming", +] [workspace.dependencies] -bevy = { version = "0.12", default-features = false } -bevy_matchbox = "0.8" +bevy = { version = "0.13", default-features = false } +bevy_matchbox = "0.9" diff --git a/bevy-rtc-macros/Cargo.toml b/bevy-rtc-macros/Cargo.toml index eed2152..e892f50 100644 --- a/bevy-rtc-macros/Cargo.toml +++ b/bevy-rtc-macros/Cargo.toml @@ -7,6 +7,7 @@ description.workspace = true repository.workspace = true authors.workspace = true keywords.workspace = true +categories.workspace = true [lib] proc-macro = true diff --git a/bevy-rtc/Cargo.toml b/bevy-rtc/Cargo.toml index e36e637..900644d 100644 --- a/bevy-rtc/Cargo.toml +++ b/bevy-rtc/Cargo.toml @@ -7,6 +7,7 @@ description.workspace = true repository.workspace = true authors.workspace = true keywords.workspace = true +categories.workspace = true [package.metadata.docs.rs] all-features = true # document all features diff --git a/bevy-rtc/src/client/plugin.rs b/bevy-rtc/src/client/plugin.rs index f89b022..d6ad3c2 100644 --- a/bevy-rtc/src/client/plugin.rs +++ b/bevy-rtc/src/client/plugin.rs @@ -18,7 +18,7 @@ impl Plugin for RtcClientPlugin { app.add_event::() .insert_resource(RtcState::default()) .add_bounded_protocol::(2) - .add_state::() + .init_state::() .add_event::() .add_event::() .add_systems( @@ -34,15 +34,13 @@ impl Plugin for RtcClientPlugin { First, (common_socket_reader, systems::client_event_writer) .chain() - .run_if(resource_exists::()), + .run_if(resource_exists::), ) .add_systems( First, systems::calculate_latency .after(systems::client_event_writer) - .run_if(state_exists_and_equals( - RtcClientStatus::Connected, - )), + .run_if(in_state(RtcClientStatus::Connected)), ) .add_systems( Update, @@ -51,9 +49,7 @@ impl Plugin for RtcClientPlugin { systems::send_latency_tracers .run_if(on_timer(Duration::from_millis(100))), ) - .run_if(state_exists_and_equals( - RtcClientStatus::Connected, - )), + .run_if(in_state(RtcClientStatus::Connected)), ); } } diff --git a/bevy-rtc/src/client/router/mod.rs b/bevy-rtc/src/client/router/mod.rs index 29551f9..3db92f3 100644 --- a/bevy-rtc/src/client/router/mod.rs +++ b/bevy-rtc/src/client/router/mod.rs @@ -44,7 +44,7 @@ impl AddProtocolExt for App { .add_systems( Last, OutgoingMessages::::send_payloads - .run_if(resource_exists::()), + .run_if(resource_exists::), ); self } @@ -68,7 +68,7 @@ impl AddProtocolExt for App { First, IncomingMessages::::receive_payloads .after(common_socket_reader) - .run_if(resource_exists::()), + .run_if(resource_exists::), ); self } @@ -98,12 +98,12 @@ impl AddProtocolExt for App { First, IncomingMessages::::receive_payloads .after(common_socket_reader) - .run_if(resource_exists::()), + .run_if(resource_exists::), ) .add_systems( Last, OutgoingMessages::::send_payloads - .run_if(resource_exists::()), + .run_if(resource_exists::), ); self } diff --git a/bevy-rtc/src/client/system_params.rs b/bevy-rtc/src/client/system_params.rs index 449907e..ad27543 100644 --- a/bevy-rtc/src/client/system_params.rs +++ b/bevy-rtc/src/client/system_params.rs @@ -8,6 +8,21 @@ pub struct NetworkReader<'w, M: Payload> { } impl<'w, M: Payload> NetworkReader<'w, M> { + /// Returns the capacity of this network reader. + pub fn capacity(&self) -> usize { + self.incoming.bound + } + + /// Returns the number of messages waiting in the buffer without draining them. + pub fn len(&self) -> usize { + self.incoming.messages.len() + } + + /// Returns the number of messages waiting in the buffer without draining them. + pub fn is_empty(&self) -> bool { + self.incoming.messages.is_empty() + } + /// Consumes all messages in the buffer and iterate on them. pub fn read(&mut self) -> std::collections::vec_deque::Drain<'_, M> { self.incoming.messages.drain(..) diff --git a/bevy-rtc/src/server/plugin.rs b/bevy-rtc/src/server/plugin.rs index c3d07e0..72fce01 100644 --- a/bevy-rtc/src/server/plugin.rs +++ b/bevy-rtc/src/server/plugin.rs @@ -22,7 +22,7 @@ impl Plugin for RtcServerPlugin { app.add_event::() .add_event::() .add_bounded_protocol::(2) - .add_state::() + .init_state::() .insert_resource(RtcState::new( (Ipv4Addr::UNSPECIFIED, self.port).into(), )) @@ -41,7 +41,7 @@ impl Plugin for RtcServerPlugin { systems::calculate_latency, ) .chain() - .run_if(resource_exists::()), + .run_if(resource_exists::), ) .add_systems( Update, @@ -50,7 +50,7 @@ impl Plugin for RtcServerPlugin { systems::send_latency_tracers .run_if(on_timer(Duration::from_millis(100))), ) - .run_if(state_exists_and_equals(RtcServerStatus::Ready)), + .run_if(in_state(RtcServerStatus::Ready)), ); } } diff --git a/bevy-rtc/src/server/router/mod.rs b/bevy-rtc/src/server/router/mod.rs index abf8f35..db4e012 100644 --- a/bevy-rtc/src/server/router/mod.rs +++ b/bevy-rtc/src/server/router/mod.rs @@ -47,7 +47,7 @@ impl AddProtocolExt for App { .add_systems( Last, OutgoingMessages::::send_payloads - .run_if(resource_exists::()), + .run_if(resource_exists::), ); self @@ -72,7 +72,7 @@ impl AddProtocolExt for App { First, IncomingMessages::::receive_payloads .after(common_socket_reader) - .run_if(resource_exists::()), + .run_if(resource_exists::), ); self @@ -107,12 +107,12 @@ impl AddProtocolExt for App { First, IncomingMessages::::receive_payloads .after(common_socket_reader) - .run_if(resource_exists::()), + .run_if(resource_exists::), ) .add_systems( Last, OutgoingMessages::::send_payloads - .run_if(resource_exists::()), + .run_if(resource_exists::), ); self diff --git a/bevy-rtc/src/server/system_params.rs b/bevy-rtc/src/server/system_params.rs index 313e2db..6544dba 100644 --- a/bevy-rtc/src/server/system_params.rs +++ b/bevy-rtc/src/server/system_params.rs @@ -10,6 +10,21 @@ pub struct NetworkReader<'w, M: Payload> { } impl<'w, M: Payload> NetworkReader<'w, M> { + /// Returns the capacity of this network reader. + pub fn capacity(&self) -> usize { + self.incoming.bound + } + + /// Returns the number of messages waiting in the buffer without draining them. + pub fn len(&self) -> usize { + self.incoming.messages.len() + } + + /// Returns the number of messages waiting in the buffer without draining them. + pub fn is_empty(&self) -> bool { + self.incoming.messages.is_empty() + } + /// Consumes all messages in the buffer and iterate on them. pub fn read(&mut self) -> Vec<(PeerId, M)> { self.incoming.messages.drain().fold( diff --git a/demos/painting-client/Cargo.toml b/demos/painting-client/Cargo.toml index 94f161f..8656ae1 100644 --- a/demos/painting-client/Cargo.toml +++ b/demos/painting-client/Cargo.toml @@ -9,5 +9,8 @@ publish = false bevy = { workspace = true, default-features = true } bevy-rtc = { path = "../../bevy-rtc", features = ["client"] } protocol = { path = "../protocol" } -bevy_egui = "0.24" +bevy_egui = "0.25" log = { version = "0.4", default-features = false } + +## FIXME: Remove this after https://github.com/bevyengine/bevy/issues/11052 +instant = { version = "0.1", features = ["wasm-bindgen"] } diff --git a/demos/painting-client/src/main.rs b/demos/painting-client/src/main.rs index 97789de..c8e735a 100644 --- a/demos/painting-client/src/main.rs +++ b/demos/painting-client/src/main.rs @@ -25,7 +25,6 @@ fn main() { WindowPlugin { primary_window: Some(bevy::window::Window { present_mode: PresentMode::AutoVsync, - fit_canvas_to_parent: true, prevent_default_event_handling: true, resolution: WindowResolution::new(450., 500.), ..default() diff --git a/demos/ping-client/src/main.rs b/demos/ping-client/src/main.rs index f8a873d..f818a16 100644 --- a/demos/ping-client/src/main.rs +++ b/demos/ping-client/src/main.rs @@ -30,9 +30,8 @@ fn main() { } } .run_if( - on_timer(Duration::from_secs(1)).and_then( - state_exists_and_equals(RtcClientStatus::Connected), - ), + on_timer(Duration::from_secs(1)) + .and_then(in_state(RtcClientStatus::Connected)), ), ) .add_systems(Update, |mut reader: NetworkReader| {