From daee384350d95ebcac780dfb100e9dc8a0946083 Mon Sep 17 00:00:00 2001 From: devil-ira Date: Wed, 1 Nov 2023 14:10:39 +0100 Subject: [PATCH] Update to Bevy 0.12 --- Cargo.toml | 1 + bevy_rapier2d/Cargo.toml | 4 ++-- bevy_rapier2d/examples/events2.rs | 4 ++-- bevy_rapier3d/Cargo.toml | 4 ++-- bevy_rapier3d/examples/events3.rs | 4 ++-- src/plugin/context.rs | 2 -- src/plugin/plugin.rs | 30 +++++++++++++------------ src/plugin/systems.rs | 37 +++++++++++++++---------------- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a0431007..3c9e5ae5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ opt-level = 1 codegen-units = 1 [patch.crates-io] +bevy = { git = "https://github.com/bevyengine/bevy" } #nalgebra = { path = "../nalgebra" } #parry2d = { path = "../parry/crates/parry2d" } #parry3d = { path = "../parry/crates/parry3d" } diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index f72a84ce..375c8198 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -32,7 +32,7 @@ headless = [] async-collider = [ "bevy/bevy_asset", "bevy/bevy_scene" ] [dependencies] -bevy = { version = "0.11", default-features = false } +bevy = { version = "0.12.0-dev", default-features = false } nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] } # Don't enable the default features because we don't need the ColliderSet/RigidBodySet rapier2d = "0.17.0" @@ -42,7 +42,7 @@ log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} [dev-dependencies] -bevy = { version = "0.11", default-features = false, features = ["x11"]} +bevy = { version = "0.12.0-dev", default-features = false, features = ["x11", "tonemapping_luts"]} oorandom = "11" approx = "0.5.1" glam = { version = "0.24", features = [ "approx" ] } diff --git a/bevy_rapier2d/examples/events2.rs b/bevy_rapier2d/examples/events2.rs index fa47816d..9df4ea7f 100644 --- a/bevy_rapier2d/examples/events2.rs +++ b/bevy_rapier2d/examples/events2.rs @@ -26,11 +26,11 @@ fn display_events( mut collision_events: EventReader, mut contact_force_events: EventReader, ) { - for collision_event in collision_events.iter() { + for collision_event in collision_events.read() { println!("Received collision event: {collision_event:?}"); } - for contact_force_event in contact_force_events.iter() { + for contact_force_event in contact_force_events.read() { println!("Received contact force event: {contact_force_event:?}"); } } diff --git a/bevy_rapier3d/Cargo.toml b/bevy_rapier3d/Cargo.toml index 6f7cd941..19e40da2 100644 --- a/bevy_rapier3d/Cargo.toml +++ b/bevy_rapier3d/Cargo.toml @@ -33,7 +33,7 @@ headless = [ ] async-collider = [ "bevy/bevy_asset", "bevy/bevy_scene" ] [dependencies] -bevy = { version = "0.11", default-features = false } +bevy = { version = "0.12.0-dev", default-features = false } nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] } # Don't enable the default features because we don't need the ColliderSet/RigidBodySet rapier3d = "0.17" @@ -43,7 +43,7 @@ log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} [dev-dependencies] -bevy = { version = "0.11", default-features = false, features = ["x11"]} +bevy = { version = "0.12.0-dev", default-features = false, features = ["x11", "tonemapping_luts"]} approx = "0.5.1" glam = { version = "0.24", features = [ "approx" ] } diff --git a/bevy_rapier3d/examples/events3.rs b/bevy_rapier3d/examples/events3.rs index d7574dc0..4d8d09b4 100644 --- a/bevy_rapier3d/examples/events3.rs +++ b/bevy_rapier3d/examples/events3.rs @@ -29,11 +29,11 @@ fn display_events( mut collision_events: EventReader, mut contact_force_events: EventReader, ) { - for collision_event in collision_events.iter() { + for collision_event in collision_events.read() { println!("Received collision event: {collision_event:?}"); } - for contact_force_event in contact_force_events.iter() { + for contact_force_event in contact_force_events.read() { println!("Received contact force event: {contact_force_event:?}"); } } diff --git a/src/plugin/context.rs b/src/plugin/context.rs index b30e824f..016609c2 100644 --- a/src/plugin/context.rs +++ b/src/plugin/context.rs @@ -737,8 +737,6 @@ impl RapierContext { aabb: bevy::render::primitives::Aabb, mut callback: impl FnMut(Entity) -> bool, ) { - #[cfg(feature = "dim2")] - use bevy::math::Vec3Swizzles; #[cfg(feature = "dim2")] let scaled_aabb = rapier::prelude::Aabb { mins: (aabb.min().xy() / self.physics_scale).into(), diff --git a/src/plugin/plugin.rs b/src/plugin/plugin.rs index fc5aa295..4ca4934a 100644 --- a/src/plugin/plugin.rs +++ b/src/plugin/plugin.rs @@ -2,10 +2,13 @@ use crate::pipeline::{CollisionEvent, ContactForceEvent}; use crate::plugin::configuration::SimulationToRenderTime; use crate::plugin::{systems, RapierConfiguration, RapierContext}; use crate::prelude::*; -use bevy::ecs::{ - event::Events, - schedule::{ScheduleLabel, SystemConfigs}, - system::SystemParamItem, +use bevy::{ + ecs::{ + event::{event_update_system, Events}, + schedule::{ScheduleLabel, SystemConfigs}, + system::SystemParamItem, + }, + utils::intern::Interned, }; use bevy::{prelude::*, transform::TransformSystem}; use std::marker::PhantomData; @@ -18,7 +21,7 @@ pub type NoUserData = (); /// This will automatically setup all the resources needed to run a physics simulation with the /// Rapier physics engine. pub struct RapierPhysicsPlugin { - schedule: Box, + schedule: Interned, physics_scale: f32, default_system_setup: bool, _phantom: PhantomData, @@ -68,7 +71,7 @@ where /// Adds the physics systems to the provided schedule rather than `PostUpdate`. pub fn in_schedule(mut self, schedule: impl ScheduleLabel) -> Self { - self.schedule = Box::new(schedule); + self.schedule = schedule.intern(); self } @@ -88,7 +91,7 @@ where .chain() .in_set(RapierTransformPropagateSet), #[cfg(all(feature = "dim3", feature = "async-collider"))] - systems::init_async_scene_colliders.after(bevy::scene::scene_spawner_system), + systems::init_async_scene_colliders, #[cfg(all(feature = "dim3", feature = "async-collider"))] systems::init_async_colliders, systems::init_rigid_bodies, @@ -107,9 +110,9 @@ where .into_configs(), PhysicsSet::StepSimulation => ( systems::step_simulation::, - Events::::update_system + event_update_system:: .before(systems::step_simulation::), - Events::::update_system + event_update_system:: .before(systems::step_simulation::), ) .into_configs(), @@ -117,8 +120,7 @@ where systems::update_colliding_entities, systems::writeback_rigid_bodies, systems::writeback_mass_properties, - Events::::update_system - .after(systems::writeback_mass_properties), + event_update_system::.after(systems::writeback_mass_properties), ) .into_configs(), } @@ -134,7 +136,7 @@ pub struct RapierTransformPropagateSet; impl Default for RapierPhysicsPlugin { fn default() -> Self { Self { - schedule: Box::new(PostUpdate), + schedule: PostUpdate.intern(), physics_scale: 1.0, default_system_setup: true, _phantom: PhantomData, @@ -205,7 +207,7 @@ where // Add each set as necessary if self.default_system_setup { app.configure_sets( - self.schedule.clone(), + self.schedule, ( PhysicsSet::SyncBackend, PhysicsSet::StepSimulation, @@ -219,7 +221,7 @@ where app.add_systems(PostUpdate, (systems::sync_removals,)); app.add_systems( - self.schedule.clone(), + self.schedule, ( Self::get_systems(PhysicsSet::SyncBackend).in_set(PhysicsSet::SyncBackend), Self::get_systems(PhysicsSet::StepSimulation) diff --git a/src/plugin/systems.rs b/src/plugin/systems.rs index aadbf662..7deb595e 100644 --- a/src/plugin/systems.rs +++ b/src/plugin/systems.rs @@ -21,7 +21,7 @@ use crate::prelude::{ use crate::utils; use bevy::ecs::system::{StaticSystemParam, SystemParamItem}; use bevy::prelude::*; -use rapier::prelude::*; +use rapier::{math::Real, prelude::*}; use std::collections::HashMap; #[cfg(all(feature = "dim3", feature = "async-collider"))] @@ -682,7 +682,7 @@ pub fn writeback_mass_properties( let scale = context.physics_scale; if config.physics_pipeline_active { - for entity in mass_modified.iter() { + for entity in mass_modified.read() { if let Some(handle) = context.entity2body.get(entity).copied() { if let Some(rb) = context.bodies.get(handle) { if let Ok(mut mass_props) = mass_props.get_mut(**entity) { @@ -1187,7 +1187,7 @@ pub fn sync_removals( * Rigid-bodies removal detection. */ let context = &mut *context; - for entity in removed_bodies.iter() { + for entity in removed_bodies.read() { if let Some(handle) = context.entity2body.remove(&entity) { let _ = context.last_body_transform_set.remove(&handle); context.bodies.remove( @@ -1220,7 +1220,7 @@ pub fn sync_removals( /* * Collider removal detection. */ - for entity in removed_colliders.iter() { + for entity in removed_colliders.read() { if let Some(parent) = context.collider_parent(entity) { mass_modified.send(parent.into()); } @@ -1250,7 +1250,7 @@ pub fn sync_removals( /* * Impulse joint removal detection. */ - for entity in removed_impulse_joints.iter() { + for entity in removed_impulse_joints.read() { if let Some(handle) = context.entity2impulse_joint.remove(&entity) { context.impulse_joints.remove(handle, true); } @@ -1266,7 +1266,7 @@ pub fn sync_removals( /* * Multibody joint removal detection. */ - for entity in removed_multibody_joints.iter() { + for entity in removed_multibody_joints.read() { if let Some(handle) = context.entity2multibody_joint.remove(&entity) { context.multibody_joints.remove(handle, true); } @@ -1284,7 +1284,7 @@ pub fn sync_removals( /* * Marker components removal detection. */ - for entity in removed_sensors.iter() { + for entity in removed_sensors.read() { if let Some(handle) = context.entity2collider.get(&entity) { if let Some(co) = context.colliders.get_mut(*handle) { co.set_sensor(false); @@ -1292,7 +1292,7 @@ pub fn sync_removals( } } - for entity in removed_colliders_disabled.iter() { + for entity in removed_colliders_disabled.read() { if let Some(handle) = context.entity2collider.get(&entity) { if let Some(co) = context.colliders.get_mut(*handle) { co.set_enabled(true); @@ -1300,7 +1300,7 @@ pub fn sync_removals( } } - for entity in removed_rigid_body_disabled.iter() { + for entity in removed_rigid_body_disabled.read() { if let Some(handle) = context.entity2body.get(&entity) { if let Some(rb) = context.bodies.get_mut(*handle) { rb.set_enabled(true); @@ -1317,7 +1317,7 @@ pub fn update_colliding_entities( mut collision_events: EventReader, mut colliding_entities: Query<&mut CollidingEntities>, ) { - for event in collision_events.iter() { + for event in collision_events.read() { match event.to_owned() { CollisionEvent::Started(entity1, entity2, _) => { if let Ok(mut entities) = colliding_entities.get_mut(entity1) { @@ -1507,7 +1507,10 @@ mod tests { use bevy::{ asset::AssetPlugin, ecs::event::Events, - render::{settings::WgpuSettings, RenderPlugin}, + render::{ + settings::{RenderCreation, WgpuSettings}, + RenderPlugin, + }, scene::ScenePlugin, time::TimePlugin, window::WindowPlugin, @@ -1631,13 +1634,9 @@ mod tests { #[test] #[cfg(all(feature = "dim3", feature = "async-collider"))] fn async_scene_collider_initializes() { - use bevy::scene::scene_spawner_system; - let mut app = App::new(); - app.add_plugins(HeadlessRenderPlugin).add_systems( - Update, - init_async_scene_colliders.after(scene_spawner_system), - ); + app.add_plugins(HeadlessRenderPlugin) + .add_systems(PostUpdate, init_async_scene_colliders); let mut meshes = app.world.resource_mut::>(); let cube_handle = meshes.add(Cube::default().into()); @@ -1825,10 +1824,10 @@ mod tests { AssetPlugin::default(), ScenePlugin::default(), RenderPlugin { - wgpu_settings: WgpuSettings { + render_creation: RenderCreation::Automatic(WgpuSettings { backends: None, ..Default::default() - }, + }), }, ImagePlugin::default(), ));