Skip to content

Commit

Permalink
Upgrade to bevy 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
haihala committed Dec 12, 2024
1 parent 0179f4d commit d9e3d42
Show file tree
Hide file tree
Showing 9 changed files with 852 additions and 414 deletions.
1,168 changes: 804 additions & 364 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 @@ -118,7 +118,7 @@ pub trait OpenSocketExt<C: BuildablePlurality> {

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

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

impl CloseSocketExt for Commands<'_, '_> {
fn close_socket<C: BuildablePlurality + 'static>(&mut self) {
self.add(CloseSocket::<C>(PhantomData))
self.queue(CloseSocket::<C>(PhantomData))
}
}

Expand Down
12 changes: 9 additions & 3 deletions examples/bevy_ggrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ web-sys = { version = "0.3", features = [
] }
serde_qs = "0.13"
wasm-bindgen = "0.2"
bevy_ggrs = { version = "0.16", features = ["wasm-bindgen"] }
# Temp solution, I got bevy_ggrs to compile with bevy 0.15
# Should be version 0.17 eventually
bevy_ggrs = { git = "https://github.com/haihala/bevy_ggrs.git", branch = "main", 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 +40,9 @@ bevy = { version = "0.14", default-features = false, features = [
# gh actions runners don't like wayland
"x11",
] }
bevy_ggrs = "0.16"
# Temp solution, I got bevy_ggrs to compile with bevy 0.15
# Should be version 0.17 eventually
bevy_ggrs = { git = "https://github.com/haihala/bevy_ggrs.git", branch = "main" }
bytemuck = { version = "1.7", features = ["derive"] }
clap = { version = "4.3", features = ["derive"] }
serde = "1.0"
23 changes: 8 additions & 15 deletions examples/bevy_ggrs/src/box_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,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 @@ -126,12 +125,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 @@ -143,10 +139,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 @@ -76,40 +76,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 @@ -126,7 +123,7 @@ fn lobby_system(
args: Res<Args>,
mut socket: ResMut<MatchboxSocket<SingleChannel>>,
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 @@ -144,7 +141,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 @@ -160,7 +157,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 @@ -41,11 +41,11 @@ once_cell = { version = "1.17", default-features = false, features = [
] }
derive_more = { version = "1.0", features = ["display", "from"] }

ggrs = { version = "0.10", default-features = false, optional = true }
ggrs = { git = "https://github.com/gschup/ggrs", default-features = false, optional = true }
bincode = { version = "1.3", default-features = false, optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
ggrs = { version = "0.10", default-features = false, optional = true, features = [
ggrs = { git = "https://github.com/gschup/ggrs", default-features = false, optional = true, features = [
"wasm-bindgen",
] }
ws_stream_wasm = { version = "0.7", default-features = false }
Expand Down

0 comments on commit d9e3d42

Please sign in to comment.