Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
feat: bevy 0.13 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau authored Mar 10, 2024
1 parent 3c9ac4a commit 6092da3
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 32 deletions.
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@ This changelog follows the patterns described here: <https://keepachangelog.com/

Subheadings to categorize changes are `added, changed, deprecated, removed, fixed, security`.

## 0.9.0

### added

- Added `.capacity()`, `.len()`, and `.is_empty()` to `NetworkReader`

### changed

- To bevy 0.13

## 0.8.12

## changed
### changed

- Optimized client and server to skip deserializing packets if the bound has been reached

## fixed
### fixed

- A rare server panic when a client disconnects

## 0.8.11

## fixed
### fixed

- <docs.rs> now properly documents all features

Expand Down
16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions bevy-rtc-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description.workspace = true
repository.workspace = true
authors.workspace = true
keywords.workspace = true
categories.workspace = true

[lib]
proc-macro = true
Expand Down
1 change: 1 addition & 0 deletions bevy-rtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions bevy-rtc/src/client/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Plugin for RtcClientPlugin {
app.add_event::<SocketRecvEvent>()
.insert_resource(RtcState::default())
.add_bounded_protocol::<LatencyTracerPayload>(2)
.add_state::<RtcClientStatus>()
.init_state::<RtcClientStatus>()
.add_event::<ConnectionRequest>()
.add_event::<RtcClientEvent>()
.add_systems(
Expand All @@ -34,15 +34,13 @@ impl Plugin for RtcClientPlugin {
First,
(common_socket_reader, systems::client_event_writer)
.chain()
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
)
.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,
Expand All @@ -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)),
);
}
}
8 changes: 4 additions & 4 deletions bevy-rtc/src/client/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl AddProtocolExt for App {
.add_systems(
Last,
OutgoingMessages::<M>::send_payloads
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
);
self
}
Expand All @@ -68,7 +68,7 @@ impl AddProtocolExt for App {
First,
IncomingMessages::<M>::receive_payloads
.after(common_socket_reader)
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
);
self
}
Expand Down Expand Up @@ -98,12 +98,12 @@ impl AddProtocolExt for App {
First,
IncomingMessages::<M>::receive_payloads
.after(common_socket_reader)
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
)
.add_systems(
Last,
OutgoingMessages::<M>::send_payloads
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
);
self
}
Expand Down
15 changes: 15 additions & 0 deletions bevy-rtc/src/client/system_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)
Expand Down
6 changes: 3 additions & 3 deletions bevy-rtc/src/server/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Plugin for RtcServerPlugin {
app.add_event::<SocketRecvEvent>()
.add_event::<RtcServerEvent>()
.add_bounded_protocol::<LatencyTracerPayload>(2)
.add_state::<RtcServerStatus>()
.init_state::<RtcServerStatus>()
.insert_resource(RtcState::new(
(Ipv4Addr::UNSPECIFIED, self.port).into(),
))
Expand All @@ -41,7 +41,7 @@ impl Plugin for RtcServerPlugin {
systems::calculate_latency,
)
.chain()
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
)
.add_systems(
Update,
Expand All @@ -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)),
);
}
}
8 changes: 4 additions & 4 deletions bevy-rtc/src/server/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl AddProtocolExt for App {
.add_systems(
Last,
OutgoingMessages::<M>::send_payloads
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
);

self
Expand All @@ -72,7 +72,7 @@ impl AddProtocolExt for App {
First,
IncomingMessages::<M>::receive_payloads
.after(common_socket_reader)
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
);

self
Expand Down Expand Up @@ -107,12 +107,12 @@ impl AddProtocolExt for App {
First,
IncomingMessages::<M>::receive_payloads
.after(common_socket_reader)
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
)
.add_systems(
Last,
OutgoingMessages::<M>::send_payloads
.run_if(resource_exists::<RtcSocket>()),
.run_if(resource_exists::<RtcSocket>),
);

self
Expand Down
15 changes: 15 additions & 0 deletions bevy-rtc/src/server/system_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion demos/painting-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
1 change: 0 additions & 1 deletion demos/painting-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions demos/ping-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PingPayload>| {
Expand Down

0 comments on commit 6092da3

Please sign in to comment.