Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to bevy 0.15 #466

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,238 changes: 840 additions & 398 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ The Matchbox project contains:
- [matchbox_signaling](https://github.com/johanhelsing/matchbox/tree/main/matchbox_signaling): A signaling server library, with ready to use examples
- [matchbox_server](https://github.com/johanhelsing/matchbox/tree/main/matchbox_server): A ready to use full-mesh signalling server
- [bevy_matchbox](https://github.com/johanhelsing/matchbox/tree/main/bevy_matchbox): A `matchbox_socket` integration for the [Bevy](https://bevyengine.org/) game engine

| bevy | bevy_matchbox |
|-------|---------------|
| 0.14 | 0.10, main |
| ----- | ------------- |
| 0.15 | 0.11, main |
| 0.14 | 0.10 |
| 0.13 | 0.9 |
| 0.12 | 0.8 |
| 0.11 | 0.7 |
Expand Down
7 changes: 4 additions & 3 deletions bevy_matchbox/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_matchbox"
version = "0.10.0"
version = "0.11.0"
authors = [
"Johan Helsing <[email protected]>",
"Garry O'Donnell <[email protected]",
Expand Down Expand Up @@ -29,7 +29,7 @@ signaling = [
]

[dependencies]
bevy = { version = "0.14", default-features = false }
bevy = { version = "0.15", default-features = false }
matchbox_socket = { version = "0.10", path = "../matchbox_socket" }
cfg-if = "1.0"

Expand All @@ -38,8 +38,9 @@ matchbox_signaling = { version = "0.10", path = "../matchbox_signaling", optiona
async-compat = { version = "0.2", optional = true }

[dev-dependencies]
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_winit",
"bevy_window",
"bevy_render",
"bevy_pbr",
"bevy_core_pipeline",
Expand Down
4 changes: 2 additions & 2 deletions bevy_matchbox/src/signaling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ where
S: SignalingState,
{
fn start_server(&mut self, builder: SignalingServerBuilder<Topology, Cb, S>) {
self.add(StartServer(builder))
self.queue(StartServer(builder))
}
}

Expand All @@ -141,7 +141,7 @@ pub trait StopServerExt {

impl StopServerExt for Commands<'_, '_> {
fn stop_server(&mut self) {
self.add(StopServer)
self.queue(StopServer)
}
}

Expand Down
4 changes: 2 additions & 2 deletions bevy_matchbox/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub trait OpenSocketExt {

impl OpenSocketExt for Commands<'_, '_> {
fn open_socket(&mut self, socket_builder: WebRtcSocketBuilder) {
self.add(OpenSocket(socket_builder))
self.queue(OpenSocket(socket_builder))
}
}

Expand All @@ -137,7 +137,7 @@ pub trait CloseSocketExt {

impl CloseSocketExt for Commands<'_, '_> {
fn close_socket(&mut self) {
self.add(CloseSocket)
self.queue(CloseSocket)
}
}

Expand Down
6 changes: 3 additions & 3 deletions examples/bevy_ggrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ web-sys = { version = "0.3", features = [
] }
serde_qs = "0.13"
wasm-bindgen = "0.2"
bevy_ggrs = { version = "0.16", features = ["wasm-bindgen"] }
bevy_ggrs = { version = "0.17", features = ["wasm-bindgen"] }

[dependencies]
bevy_matchbox = { path = "../../bevy_matchbox", features = ["ggrs"] }
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_winit",
"bevy_render",
"bevy_pbr",
Expand All @@ -36,7 +36,7 @@ bevy = { version = "0.14", default-features = false, features = [
# gh actions runners don't like wayland
"x11",
] }
bevy_ggrs = "0.16"
bevy_ggrs = "0.17"
bytemuck = { version = "1.7", features = ["derive"] }
clap = { version = "4.3", features = ["derive"] }
serde = "1.0"
27 changes: 10 additions & 17 deletions examples/bevy_ggrs/src/box_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_ggrs::{
Session,
};
use bevy_matchbox::prelude::PeerId;
use bytemuck::{Pod, Zeroable};
use serde::{Deserialize, Serialize};
use std::hash::Hash;

const BLUE: Color = Color::srgb(0.8, 0.6, 0.2);
Expand All @@ -29,7 +29,7 @@ const CUBE_SIZE: f32 = 0.2;
pub type BoxConfig = GgrsConfig<BoxInput, PeerId>;

#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Pod, Zeroable)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
pub struct BoxInput {
pub inp: u8,
}
Expand Down Expand Up @@ -103,11 +103,10 @@ pub fn setup_scene(
};

// A ground plane
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(PLANE_SIZE / 2.0))),
material: materials.add(StandardMaterial::from(Color::srgb(0.3, 0.5, 0.3))),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(PLANE_SIZE / 2.0)))),
MeshMaterial3d(materials.add(StandardMaterial::from(Color::srgb(0.3, 0.5, 0.3)))),
));

let r = PLANE_SIZE / 4.;
let mesh = meshes.add(Mesh::from(Cuboid::from_size(Vec3::splat(CUBE_SIZE))));
Expand All @@ -127,12 +126,9 @@ pub fn setup_scene(
commands
.spawn((
// ...add visual information...
PbrBundle {
mesh: mesh.clone(),
material: materials.add(StandardMaterial::from(color)),
transform,
..default()
},
Mesh3d(mesh.clone()),
MeshMaterial3d(materials.add(StandardMaterial::from(color))),
transform,
// ...flags...
Player { handle },
// ...and components which will be rolled-back...
Expand All @@ -144,10 +140,7 @@ pub fn setup_scene(
}

// light
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(-4.0, 8.0, 4.0),
..default()
});
commands.spawn((PointLight::default(), Transform::from_xyz(-4.0, 8.0, 4.0)));
// camera
for mut transform in camera_query.iter_mut() {
*transform = Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y);
Expand Down
38 changes: 17 additions & 21 deletions examples/bevy_ggrs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,40 +78,37 @@ struct LobbyText;
struct LobbyUI;

fn lobby_startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera3dBundle::default());
commands.spawn(Camera3d::default());

// All this is just for spawning centered text.
commands
.spawn(NodeBundle {
style: Style {
.spawn((
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
position_type: PositionType::Absolute,
justify_content: JustifyContent::Center,
align_items: AlignItems::FlexEnd,
..default()
},
background_color: Color::srgb(0.43, 0.41, 0.38).into(),
..default()
})
BackgroundColor(Color::srgb(0.43, 0.41, 0.38)),
))
.with_children(|parent| {
parent
.spawn(TextBundle {
style: Style {
.spawn((
Node {
align_self: AlignSelf::Center,
justify_content: JustifyContent::Center,
..default()
},
text: Text::from_section(
"Entering lobby...",
TextStyle {
font: asset_server.load("fonts/quicksand-light.ttf"),
font_size: 96.,
color: Color::BLACK,
},
),
..default()
})
Text("Entering lobby...".to_string()),
TextFont {
font: asset_server.load("fonts/quicksand-light.ttf"),
font_size: 96.,
..default()
},
TextColor(Color::BLACK),
))
.insert(LobbyText);
})
.insert(LobbyUI);
Expand All @@ -128,7 +125,7 @@ fn lobby_system(
args: Res<Args>,
mut socket: ResMut<MatchboxSocket>,
mut commands: Commands,
mut query: Query<&mut Text, With<LobbyText>>,
mut text: Single<&mut Text, With<LobbyText>>,
) {
// regularly call update_peers to update the list of connected peers
let Ok(peer_changes) = socket.try_update_peers() else {
Expand All @@ -146,7 +143,7 @@ fn lobby_system(

let connected_peers = socket.connected_peers().count();
let remaining = args.players - (connected_peers + 1);
query.single_mut().sections[0].value = format!("Waiting for {remaining} more player(s)",);
text.0 = format!("Waiting for {remaining} more player(s)",);
if remaining > 0 {
return;
}
Expand All @@ -162,7 +159,6 @@ fn lobby_system(
let mut sess_build = SessionBuilder::<BoxConfig>::new()
.with_num_players(args.players)
.with_max_prediction_window(max_prediction)
.unwrap()
.with_input_delay(2)
.with_fps(FPS)
.expect("invalid fps");
Expand Down
4 changes: 2 additions & 2 deletions matchbox_socket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ once_cell = { version = "1.17", default-features = false, features = [
derive_more = { version = "1.0", features = ["display", "from"] }
tokio-util = { version = "0.7", features = ["io", "compat"] }

ggrs = { version = "0.10", default-features = false, optional = true }
ggrs = { version = "0.11", default-features = false, optional = true }
bincode = { version = "1.3", default-features = false, optional = true }
bytes = { version = "1.1", default-features = false }

[target.'cfg(target_arch = "wasm32")'.dependencies]
ggrs = { version = "0.10", default-features = false, optional = true, features = [
ggrs = { version = "0.11", default-features = false, optional = true, features = [
"wasm-bindgen",
] }
ws_stream_wasm = { version = "0.7", default-features = false }
Expand Down
Loading