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

Update to Bevy 0.14 #111

Merged
merged 1 commit into from
Jul 11, 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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ categories = ["network-programming", "game-development"]
wasm-bindgen = ["instant/wasm-bindgen", "ggrs/wasm-bindgen"]

[dependencies]
bevy = { version = "0.13", default-features = false }
bevy = { version = "0.14", default-features = false }
bytemuck = { version = "1.7", features = ["derive"] }
instant = { version = "0.1", optional = true }
log = "0.4"
Expand All @@ -25,7 +25,7 @@ ggrs = { git = "/~https://github.com/gschup/ggrs", features = ["sync-send"] }
seahash = "4.1"

[dev-dependencies]
bevy = { version = "0.13", default-features = true }
bevy = { version = "0.14", default-features = true }
clap = { version = "4.4", features = ["derive"] }
rand = "0.8.4"
rand_xoshiro = "0.6"
Expand Down
19 changes: 8 additions & 11 deletions examples/box_game/box_game.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use bevy::{prelude::*, render::mesh::PlaneMeshBuilder, utils::HashMap};
use bevy::{prelude::*, utils::HashMap};
use bevy_ggrs::{
AddRollbackCommandExtension, GgrsConfig, LocalInputs, LocalPlayers, PlayerInputs, Rollback,
Session,
};
use bytemuck::{Pod, Zeroable};
use std::hash::Hash;

const BLUE: Color = Color::rgb(0.8, 0.6, 0.2);
const ORANGE: Color = Color::rgb(0., 0.35, 0.8);
const MAGENTA: Color = Color::rgb(0.9, 0.2, 0.2);
const GREEN: Color = Color::rgb(0.35, 0.7, 0.35);
const BLUE: Color = Color::srgb(0.8, 0.6, 0.2);
const ORANGE: Color = Color::srgb(0., 0.35, 0.8);
const MAGENTA: Color = Color::srgb(0.9, 0.2, 0.2);
const GREEN: Color = Color::srgb(0.35, 0.7, 0.35);
const PLAYER_COLORS: [Color; 4] = [BLUE, ORANGE, MAGENTA, GREEN];

const INPUT_UP: u8 = 1 << 0;
Expand Down Expand Up @@ -95,16 +95,13 @@ pub fn setup_system(

// A ground plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(PlaneMeshBuilder {
plane: Plane3d::new(Vec3::Y),
half_size: Vec2::splat(PLANE_SIZE / 2.0),
})),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
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()
});

let r = PLANE_SIZE / 4.;
let mesh = meshes.add(Mesh::from(Cuboid::from_size(Vec3::splat(CUBE_SIZE))));
let mesh = meshes.add(Cuboid::from_length(CUBE_SIZE));

for handle in 0..num_players {
let rot = handle as f32 / num_players as f32 * 2. * std::f32::consts::PI;
Expand Down
6 changes: 4 additions & 2 deletions examples/stress_tests/particles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use bevy::{math::vec3, prelude::*, utils::HashMap, window::WindowResolution};
use bevy::{
color::palettes::css::ORANGE, math::vec3, prelude::*, utils::HashMap, window::WindowResolution,
};
use bevy_ggrs::{checksum_hasher, prelude::*, LocalInputs, LocalPlayers};
use clap::Parser;
use ggrs::{DesyncDetection, UdpNonBlockingSocket};
Expand Down Expand Up @@ -260,7 +262,7 @@ fn spawn_particles(mut commands: Commands, args: Res<Args>, mut rng: ResMut<Part
.spawn((
SpriteBundle {
sprite: Sprite {
color: Color::ORANGE,
color: ORANGE.into(),
custom_size: Some(Vec2::splat(5.0)),
..default()
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pub trait GgrsApp {

impl GgrsApp for App {
fn set_rollback_schedule_fps(&mut self, fps: usize) -> &mut Self {
self.world.insert_resource(RollbackFrameRate(fps));
self.world_mut().insert_resource(RollbackFrameRate(fps));

self
}
Expand Down
14 changes: 7 additions & 7 deletions tests/entity_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,28 @@ fn entity_mapping() {
// Re-usable queries
let get_queries = |app: &mut App| {
(
app.world.query::<(&ChildEntity, &Parent)>(),
app.world.query::<(&ParentEntity, &Children)>(),
app.world_mut().query::<(&ChildEntity, &Parent)>(),
app.world_mut().query::<(&ParentEntity, &Children)>(),
)
};

// Update once, the world should now be setup
app.update();
let (mut child_query, mut parent_query) = get_queries(&mut app);
assert!(
child_query.get_single(&app.world).is_ok(),
child_query.get_single(app.world()).is_ok(),
"Child doesn't exist"
);
assert!(
parent_query.get_single(&app.world).is_ok(),
parent_query.get_single(app.world()).is_ok(),
"Parent doesn't exist"
);

sleep();
app.update();

// Send the event to delete the child entity
app.world
app.world_mut()
.resource_mut::<Events<DeleteChildEntityEvent>>()
.send(DeleteChildEntityEvent);

Expand All @@ -138,11 +138,11 @@ fn entity_mapping() {
// Make sure the child is delete and the parent still exists
let (mut child_query, mut parent_query) = get_queries(&mut app);
assert!(
child_query.get_single(&app.world).is_err(),
child_query.get_single(app.world()).is_err(),
"Child exists after deletion"
);
assert!(
parent_query.get_single(&app.world).is_ok(),
parent_query.get_single(app.world()).is_ok(),
"Parent doesn't exist"
);
}
10 changes: 5 additions & 5 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ fn it_runs_advance_frame_schedule_systems() -> Result<(), Box<dyn std::error::Er
app2.update();
}

let frame_count1 = app1.world.get_resource::<FrameCount>().unwrap();
let frame_count2 = app2.world.get_resource::<FrameCount>().unwrap();
let frame_count1 = app1.world().get_resource::<FrameCount>().unwrap();
let frame_count2 = app2.world().get_resource::<FrameCount>().unwrap();

// We've run Bevy for 50 frames, bevy_ggrs, however needs a couple of frames
// to sync before it starts to run the advance frame schedule, so the
Expand All @@ -63,8 +63,8 @@ fn it_syncs_rollback_components() -> Result<(), Box<dyn std::error::Error>> {
app2.update();
}

let mut app2_query = app2.world.query::<(&Transform, &PlayerComponent)>();
for (transform, player) in app2_query.iter(&app2.world) {
let mut app2_query = app2.world_mut().query::<(&Transform, &PlayerComponent)>();
for (transform, player) in app2_query.iter(app2.world()) {
if player.handle == player1.handle {
assert!(transform.translation.z < 0., "Remote player moves forward");
}
Expand Down Expand Up @@ -162,7 +162,7 @@ pub fn increase_frame_system(mut frame_count: ResMut<FrameCount>) {
}

fn press_key(app: &mut App, key: KeyCode) {
app.world.send_event(KeyboardInput {
app.world_mut().send_event(KeyboardInput {
logical_key: Key::Character("w".into()),
key_code: key,
state: ButtonState::Pressed,
Expand Down
Loading